]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp
Vendor import of libc++ trunk r302418:
[FreeBSD/FreeBSD.git] / test / std / utilities / template.bitset / bitset.cons / ull_ctor.pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // test bitset(unsigned long long val);
11
12 #include <bitset>
13 #include <cassert>
14 #include <algorithm> // for 'min' and 'max'
15 #include <cstddef>
16
17 #include "test_macros.h"
18
19 #if defined(TEST_COMPILER_C1XX)
20 #pragma warning(disable: 6294) // Ill-defined for-loop:  initial condition does not satisfy test.  Loop body not executed.
21 #endif
22
23 template <std::size_t N>
24 void test_val_ctor()
25 {
26     {
27         TEST_CONSTEXPR std::bitset<N> v(0xAAAAAAAAAAAAAAAAULL);
28         assert(v.size() == N);
29         std::size_t M = std::min<std::size_t>(N, 64);
30         for (std::size_t i = 0; i < M; ++i)
31             assert(v[i] == ((i & 1) != 0));
32         for (std::size_t i = M; i < N; ++i)
33             assert(v[i] == false);
34     }
35 #if TEST_STD_VER >= 11
36     {
37         constexpr std::bitset<N> v(0xAAAAAAAAAAAAAAAAULL);
38         static_assert(v.size() == N, "");
39     }
40 #endif
41 }
42
43 int main()
44 {
45     test_val_ctor<0>();
46     test_val_ctor<1>();
47     test_val_ctor<31>();
48     test_val_ctor<32>();
49     test_val_ctor<33>();
50     test_val_ctor<63>();
51     test_val_ctor<64>();
52     test_val_ctor<65>();
53     test_val_ctor<1000>();
54 }