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(); 11 12 #include <bitset> 13 #include <cstdlib> 14 #include <cassert> 15 16 #pragma clang diagnostic ignored "-Wtautological-compare" 17 18 template <std::size_t N> 19 std::bitset<N> make_bitset()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 28 template <std::size_t N> test_flip_all()29void test_flip_all() 30 { 31 std::bitset<N> v1 = make_bitset<N>(); 32 std::bitset<N> v2 = v1; 33 v2.flip(); 34 for (std::size_t i = 0; i < N; ++i) 35 assert(v2[i] == ~v1[i]); 36 } 37 main()38int main() 39 { 40 test_flip_all<0>(); 41 test_flip_all<1>(); 42 test_flip_all<31>(); 43 test_flip_all<32>(); 44 test_flip_all<33>(); 45 test_flip_all<63>(); 46 test_flip_all<64>(); 47 test_flip_all<65>(); 48 test_flip_all<1000>(); 49 } 50