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