flip_one.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 bitset<N>& flip(size_t pos);
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_flip_one()
28{
29    std::bitset<N> v = make_bitset<N>();
30    try
31    {
32        v.flip(50);
33        bool b = v[50];
34        if (50 >= v.size())
35            assert(false);
36        assert(v[50] == b);
37        v.flip(50);
38        assert(v[50] != b);
39        v.flip(50);
40        assert(v[50] == b);
41    }
42    catch (std::out_of_range&)
43    {
44    }
45}
46
47int main()
48{
49    test_flip_one<0>();
50    test_flip_one<1>();
51    test_flip_one<31>();
52    test_flip_one<32>();
53    test_flip_one<33>();
54    test_flip_one<63>();
55    test_flip_one<64>();
56    test_flip_one<65>();
57    test_flip_one<1000>();
58}
59