| 1 | // { dg-do compile { target c++23 } } |
| 2 | |
| 3 | #include <bitset> |
| 4 | #include <string> |
| 5 | #include <testsuite_hooks.h> |
| 6 | |
| 7 | constexpr bool |
| 8 | test_indexing() |
| 9 | { |
| 10 | std::bitset<100> b("10010110"); |
| 11 | VERIFY( b[0] == 0 ); |
| 12 | VERIFY( b[1] == 1 ); |
| 13 | const auto& cb = b; |
| 14 | VERIFY( cb[0] == 0 ); |
| 15 | VERIFY( cb[1] == 1 ); |
| 16 | b[1].flip(); |
| 17 | VERIFY( cb[1] == 0 ); |
| 18 | VERIFY( b[1] == 0 ); |
| 19 | VERIFY( ~b[1] == 1 ); |
| 20 | b[3] = true; |
| 21 | bool b3 = b[3]; |
| 22 | VERIFY( b3 ); |
| 23 | b[4] = b[3]; |
| 24 | return true; |
| 25 | } |
| 26 | |
| 27 | static_assert( test_indexing() ); |
| 28 | |
| 29 | #if _GLIBCXX_USE_CXX11_ABI |
| 30 | constexpr bool |
| 31 | test_to_string() |
| 32 | { |
| 33 | std::string str = "01101001"; |
| 34 | return std::bitset<8>(str).to_string() == str; |
| 35 | } |
| 36 | |
| 37 | static_assert( test_to_string() ); |
| 38 | #endif |
| 39 | |
| 40 | constexpr bool |
| 41 | test_to_ulong() |
| 42 | { |
| 43 | unsigned long val = 0xcabba123; |
| 44 | return std::bitset<100>(val).to_ulong() == val; |
| 45 | } |
| 46 | |
| 47 | static_assert( test_to_ulong() ); |
| 48 | |
| 49 | constexpr bool |
| 50 | test_to_ullong() |
| 51 | { |
| 52 | unsigned long long val = 0x0123abcd0123abcd; |
| 53 | return std::bitset<100>(val).to_ullong() == val; |
| 54 | } |
| 55 | |
| 56 | static_assert( test_to_ullong() ); |