xref: /minix3/external/bsd/libc++/dist/libcxx/test/utilities/template.bitset/bitset.members/test.pass.cpp (revision 4684ddb6aab0b36791c8099bc705d6140b3d05d0)
1*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
2*4684ddb6SLionel Sambuc //
3*4684ddb6SLionel Sambuc //                     The LLVM Compiler Infrastructure
4*4684ddb6SLionel Sambuc //
5*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
6*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
7*4684ddb6SLionel Sambuc //
8*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
9*4684ddb6SLionel Sambuc 
10*4684ddb6SLionel Sambuc // test constexpr bool test(size_t pos) const;
11*4684ddb6SLionel Sambuc 
12*4684ddb6SLionel Sambuc #include <bitset>
13*4684ddb6SLionel Sambuc #include <cstdlib>
14*4684ddb6SLionel Sambuc #include <cassert>
15*4684ddb6SLionel Sambuc 
16*4684ddb6SLionel Sambuc #pragma clang diagnostic ignored "-Wtautological-compare"
17*4684ddb6SLionel Sambuc 
18*4684ddb6SLionel Sambuc template <std::size_t N>
19*4684ddb6SLionel Sambuc std::bitset<N>
make_bitset()20*4684ddb6SLionel Sambuc make_bitset()
21*4684ddb6SLionel Sambuc {
22*4684ddb6SLionel Sambuc     std::bitset<N> v;
23*4684ddb6SLionel Sambuc     for (std::size_t i = 0; i < N; ++i)
24*4684ddb6SLionel Sambuc         v[i] = static_cast<bool>(std::rand() & 1);
25*4684ddb6SLionel Sambuc     return v;
26*4684ddb6SLionel Sambuc }
27*4684ddb6SLionel Sambuc 
28*4684ddb6SLionel Sambuc template <std::size_t N>
test_test()29*4684ddb6SLionel Sambuc void test_test()
30*4684ddb6SLionel Sambuc {
31*4684ddb6SLionel Sambuc     const std::bitset<N> v1 = make_bitset<N>();
32*4684ddb6SLionel Sambuc     try
33*4684ddb6SLionel Sambuc     {
34*4684ddb6SLionel Sambuc         bool b = v1.test(50);
35*4684ddb6SLionel Sambuc         if (50 >= v1.size())
36*4684ddb6SLionel Sambuc             assert(false);
37*4684ddb6SLionel Sambuc         assert(b == v1[50]);
38*4684ddb6SLionel Sambuc     }
39*4684ddb6SLionel Sambuc     catch (std::out_of_range&)
40*4684ddb6SLionel Sambuc     {
41*4684ddb6SLionel Sambuc     }
42*4684ddb6SLionel Sambuc }
43*4684ddb6SLionel Sambuc 
main()44*4684ddb6SLionel Sambuc int main()
45*4684ddb6SLionel Sambuc {
46*4684ddb6SLionel Sambuc     test_test<0>();
47*4684ddb6SLionel Sambuc     test_test<1>();
48*4684ddb6SLionel Sambuc     test_test<31>();
49*4684ddb6SLionel Sambuc     test_test<32>();
50*4684ddb6SLionel Sambuc     test_test<33>();
51*4684ddb6SLionel Sambuc     test_test<63>();
52*4684ddb6SLionel Sambuc     test_test<64>();
53*4684ddb6SLionel Sambuc     test_test<65>();
54*4684ddb6SLionel Sambuc     test_test<1000>();
55*4684ddb6SLionel Sambuc }
56