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