• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #if defined(TEST_COMPILER_C1XX)
19 #pragma warning(disable: 6294) // Ill-defined for-loop:  initial condition does not satisfy test.  Loop body not executed.
20 #endif
21 
22 template <std::size_t N>
test_val_ctor()23 void test_val_ctor()
24 {
25     {
26         TEST_CONSTEXPR std::bitset<N> v(0xAAAAAAAAAAAAAAAAULL);
27         assert(v.size() == N);
28         std::size_t M = std::min<std::size_t>(v.size(), 64);
29         for (std::size_t i = 0; i < M; ++i)
30             assert(v[i] == ((i & 1) != 0));
31         for (std::size_t i = M; i < v.size(); ++i)
32             assert(v[i] == false);
33     }
34 #if TEST_STD_VER >= 11
35     {
36         constexpr std::bitset<N> v(0xAAAAAAAAAAAAAAAAULL);
37         static_assert(v.size() == N, "");
38     }
39 #endif
40 }
41 
main(int,char **)42 int main(int, char**)
43 {
44     test_val_ctor<0>();
45     test_val_ctor<1>();
46     test_val_ctor<31>();
47     test_val_ctor<32>();
48     test_val_ctor<33>();
49     test_val_ctor<63>();
50     test_val_ctor<64>();
51     test_val_ctor<65>();
52     test_val_ctor<1000>();
53 
54   return 0;
55 }
56