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 test(size_t pos) const;
11 
12 #include <bitset>
13 #include <cstdlib>
14 #include <cassert>
15 
16 #pragma clang diagnostic ignored "-Wtautological-compare"
17 
18 template <std::size_t N>
19 std::bitset<N>
make_bitset()20 make_bitset()
21 {
22     std::bitset<N> v;
23     for (std::size_t i = 0; i < N; ++i)
24         v[i] = static_cast<bool>(std::rand() & 1);
25     return v;
26 }
27 
28 template <std::size_t N>
test_test()29 void test_test()
30 {
31     const std::bitset<N> v1 = make_bitset<N>();
32     try
33     {
34         bool b = v1.test(50);
35         if (50 >= v1.size())
36             assert(false);
37         assert(b == v1[50]);
38     }
39     catch (std::out_of_range&)
40     {
41     }
42 }
43 
main()44 int main()
45 {
46     test_test<0>();
47     test_test<1>();
48     test_test<31>();
49     test_test<32>();
50     test_test<33>();
51     test_test<63>();
52     test_test<64>();
53     test_test<65>();
54     test_test<1000>();
55 }
56