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