blob: 3e09b202097d87157e17dc354db59baa04bfe085 [file] [log] [blame]
Howard Hinnantc52f43e2010-08-22 00:59:46 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc52f43e2010-08-22 00:59:46 +00007//
8//===----------------------------------------------------------------------===//
9
10// test bitset<N>& flip(size_t pos);
11
12#include <bitset>
13#include <cstdlib>
14#include <cassert>
15
Howard Hinnant97ecd642011-05-17 19:12:55 +000016#pragma clang diagnostic ignored "-Wtautological-compare"
17
Howard Hinnantc52f43e2010-08-22 00:59:46 +000018template <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}