index_const.pass.cpp revision bc8d3f97eb5c958007f2713238472e0c1c8fe02c
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 operator[](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_index_const()
28{
29    const std::bitset<N> v1 = make_bitset<N>();
30    if (N > 0)
31    {
32        assert(v1[N/2] == v1.test(N/2));
33    }
34}
35
36int main()
37{
38    test_index_const<0>();
39    test_index_const<1>();
40    test_index_const<31>();
41    test_index_const<32>();
42    test_index_const<33>();
43    test_index_const<63>();
44    test_index_const<64>();
45    test_index_const<65>();
46    test_index_const<1000>();
47}
48