test.pass.cpp revision f5256e16dfc425c1d466f6308d4026d529ce9e0b
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. 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
16template <std::size_t N>
17std::bitset<N>
18make_bitset()
19{
20    std::bitset<N> v;
21    for (std::size_t i = 0; i < N; ++i)
22        v[i] = static_cast<bool>(std::rand() & 1);
23    return v;
24}
25
26template <std::size_t N>
27void test_test()
28{
29    const std::bitset<N> v1 = make_bitset<N>();
30    try
31    {
32        bool b = v1.test(50);
33        if (50 >= v1.size())
34            assert(false);
35        assert(b == v1[50]);
36    }
37    catch (std::out_of_range&)
38    {
39    }
40}
41
42
43int main()
44{
45    test_test<0>();
46    test_test<1>();
47    test_test<31>();
48    test_test<32>();
49    test_test<33>();
50    test_test<63>();
51    test_test<64>();
52    test_test<65>();
53    test_test<1000>();
54}
55