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: 11 12 // bool operator==(const bitset<N>& rhs) const; 13 // bool operator!=(const bitset<N>& rhs) const; 14 15 #include <bitset> 16 #include <cstdlib> 17 #include <cassert> 18 19 #pragma clang diagnostic ignored "-Wtautological-compare" 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_equality() 33 { 34 const std::bitset<N> v1 = make_bitset<N>(); 35 std::bitset<N> v2 = v1; 36 assert(v1 == v2); 37 if (N > 0) 38 { 39 v2[N/2].flip(); 40 assert(v1 != v2); 41 } 42 } 43 44 int main() 45 { 46 test_equality<0>(); 47 test_equality<1>(); 48 test_equality<31>(); 49 test_equality<32>(); 50 test_equality<33>(); 51 test_equality<63>(); 52 test_equality<64>(); 53 test_equality<65>(); 54 test_equality<1000>(); 55 } 56