xref: /llvm-project/libcxx/test/std/utilities/template.bitset/bitset.members/index_const.pass.cpp (revision e5eb7049eb45f960dd7927e037a637a175d3f6db)
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 constexpr bool operator[](size_t pos) const;
11 
12 #include <bitset>
13 #include <cstdlib>
14 #include <cassert>
15 
16 #if defined(__clang__)
17 #pragma clang diagnostic ignored "-Wtautological-compare"
18 #endif
19 
20 template <std::size_t N>
21 std::bitset<N>
22 make_bitset()
23 {
24     std::bitset<N> v;
25     for (std::size_t i = 0; i < N; ++i)
26         v[i] = static_cast<bool>(std::rand() & 1);
27     return v;
28 }
29 
30 template <std::size_t N>
31 void test_index_const()
32 {
33     const std::bitset<N> v1 = make_bitset<N>();
34     if (N > 0)
35     {
36         assert(v1[N/2] == v1.test(N/2));
37     }
38 }
39 
40 int main()
41 {
42     test_index_const<0>();
43     test_index_const<1>();
44     test_index_const<31>();
45     test_index_const<32>();
46     test_index_const<33>();
47     test_index_const<63>();
48     test_index_const<64>();
49     test_index_const<65>();
50     test_index_const<1000>();
51 }
52