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