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 // test bitset(unsigned long long val);
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 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 
main(int,char **)40 int main(int, char**)
41 {
42     test_val_ctor<0>();
43     test_val_ctor<1>();
44     test_val_ctor<31>();
45     test_val_ctor<32>();
46     test_val_ctor<33>();
47     test_val_ctor<63>();
48     test_val_ctor<64>();
49     test_val_ctor<65>();
50     test_val_ctor<1000>();
51 
52   return 0;
53 }
54