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