xref: /llvm-project/libcxx/test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp (revision f02120fba28f2352fd9396683892fc6671caa137)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // bitset(unsigned long long val); // constexpr since C++23
10 
11 #include <bitset>
12 #include <cassert>
13 #include <algorithm> // for 'min' and 'max'
14 #include <cstddef>
15 
16 #include "test_macros.h"
17 
18 TEST_MSVC_DIAGNOSTIC_IGNORED(6294) // Ill-defined for-loop:  initial condition does not satisfy test.  Loop body not executed.
19 
20 template <std::size_t N>
test_val_ctor()21 TEST_CONSTEXPR_CXX23 void test_val_ctor()
22 {
23     {
24         TEST_CONSTEXPR std::bitset<N> v(0xAAAAAAAAAAAAAAAAULL);
25         assert(v.size() == N);
26         std::size_t M = std::min<std::size_t>(v.size(), 64);
27         for (std::size_t i = 0; i < M; ++i)
28             assert(v[i] == ((i & 1) != 0));
29         for (std::size_t i = M; i < v.size(); ++i)
30             assert(v[i] == false);
31     }
32 #if TEST_STD_VER >= 11
33     {
34         constexpr std::bitset<N> v(0xAAAAAAAAAAAAAAAAULL);
35         static_assert(v.size() == N, "");
36     }
37 #endif
38 }
39 
test()40 TEST_CONSTEXPR_CXX23 bool test() {
41   test_val_ctor<0>();
42   test_val_ctor<1>();
43   test_val_ctor<31>();
44   test_val_ctor<32>();
45   test_val_ctor<33>();
46   test_val_ctor<63>();
47   test_val_ctor<64>();
48   test_val_ctor<65>();
49   test_val_ctor<1000>();
50 
51   return true;
52 }
53 
main(int,char **)54 int main(int, char**)
55 {
56   test();
57 #if TEST_STD_VER > 20
58   static_assert(test());
59 #endif
60 
61   return 0;
62 }
63