File: constexpr_c%2B%2B23.cc

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (57 lines) | stat: -rw-r--r-- 1,567 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// { dg-do compile { target c++23 } }
// This test relies on std::string.
// { dg-require-effective-target hosted }
// { dg-add-options no_pch }

#include <bitset>

#ifndef __cpp_lib_constexpr_bitset
# error "Feature-test macro for constexpr bitset missing in <bitset>"
#elif __cpp_lib_constexpr_bitset != 202202L
# error "Feature-test macro for constexpr bitset has wrong value in <bitset>"
#endif

#include <testsuite_hooks.h>

constexpr bool test_ntbs()
{
  VERIFY( std::bitset<0>("000").all() );
  VERIFY( std::bitset<0>("000", 2).all() );
  VERIFY( std::bitset<1>("100", 2).all() );
  VERIFY( std::bitset<1>("z00", 2, 'z').none() );
  VERIFY( std::bitset<2>("ab0", 3, 'a', 'b').count() == 1 );

  return true;
}

static_assert( test_ntbs() );

#if _GLIBCXX_USE_CXX11_ABI
constexpr bool test_string()
{
  using S = std::string;
  VERIFY( std::bitset<0>(S("000")).all() );
  VERIFY( std::bitset<1>(S("010"), 1, 2).all() );
  VERIFY( std::bitset<2>(S("0110"), 1, 2).all() );
  VERIFY( std::bitset<2>(S("1z110"), 1, 3, 'z').count() == 1 );
  VERIFY( std::bitset<3>(S("0abab0"), 2, 3, 'a', 'b').count() == 2 );

  return true;
}

static_assert( test_string() );

constexpr bool test_wstring()
{
  using S = std::wstring;
  VERIFY( std::bitset<0>(S(L"000")).all() );
  VERIFY( std::bitset<1>(S(L"010"), 1, 2).all() );
  VERIFY( std::bitset<2>(S(L"0110"), 1, 2).all() );
  VERIFY( std::bitset<2>(S(L"1z110"), 1, 3, L'z').count() == 1 );
  VERIFY( std::bitset<3>(S(L"0abab0"), 2, 3, L'a', L'b').count() == 2 );

  return true;
}

static_assert( test_wstring() );
#endif