Debian Codegraph @

libstdc++-v3/testsuite/20_util/bitset/cons/constexpr_c++23.cc

raw
1 // { dg-do compile { target c++23 } }
2 // This test relies on std::string.
3 // { dg-require-effective-target hosted }
4 // { dg-add-options no_pch }
5
6 #include <bitset>
7
8 #ifndef __cpp_lib_constexpr_bitset
9 # error "Feature-test macro for constexpr bitset missing in <bitset>"
10 #elif __cpp_lib_constexpr_bitset != 202202L
11 # error "Feature-test macro for constexpr bitset has wrong value in <bitset>"
12 #endif
13
14 #include <testsuite_hooks.h>
15
16 constexpr bool test_ntbs()
17 {
18 VERIFY( std::bitset<0>("000").all() );
19 VERIFY( std::bitset<0>("000", 2).all() );
20 VERIFY( std::bitset<1>("100", 2).all() );
21 VERIFY( std::bitset<1>("z00", 2, 'z').none() );
22 VERIFY( std::bitset<2>("ab0", 3, 'a', 'b').count() == 1 );
23
24 return true;
25 }
26
27 static_assert( test_ntbs() );
28
29 #if _GLIBCXX_USE_CXX11_ABI
30 constexpr bool test_string()
31 {
32 using S = std::string;
33 VERIFY( std::bitset<0>(S("000")).all() );
34 VERIFY( std::bitset<1>(S("010"), 1, 2).all() );
35 VERIFY( std::bitset<2>(S("0110"), 1, 2).all() );
36 VERIFY( std::bitset<2>(S("1z110"), 1, 3, 'z').count() == 1 );
37 VERIFY( std::bitset<3>(S("0abab0"), 2, 3, 'a', 'b').count() == 2 );
38
39 return true;
40 }
41
42 static_assert( test_string() );
43
44 constexpr bool test_wstring()
45 {
46 using S = std::wstring;
47 VERIFY( std::bitset<0>(S(L"000")).all() );
48 VERIFY( std::bitset<1>(S(L"010"), 1, 2).all() );
49 VERIFY( std::bitset<2>(S(L"0110"), 1, 2).all() );
50 VERIFY( std::bitset<2>(S(L"1z110"), 1, 3, L'z').count() == 1 );
51 VERIFY( std::bitset<3>(S(L"0abab0"), 2, 3, L'a', L'b').count() == 2 );
52
53 return true;
54 }
55
56 static_assert( test_wstring() );
57 #endif