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 #include "test_macros.h" 21 22 #if defined(TEST_COMPILER_CLANG) 23 #pragma clang diagnostic ignored "-Wtautological-compare" 24 #elif defined(TEST_COMPILER_C1XX) 25 #pragma warning(disable: 6294) // Ill-defined for-loop: initial condition does not satisfy test. Loop body not executed. 26 #endif 27 28 template <std::size_t N> 29 std::bitset<N> make_bitset()30make_bitset() 31 { 32 std::bitset<N> v; 33 for (std::size_t i = 0; i < N; ++i) 34 v[i] = static_cast<bool>(std::rand() & 1); 35 return v; 36 } 37 38 template <std::size_t N> test_equality()39void test_equality() 40 { 41 const std::bitset<N> v1 = make_bitset<N>(); 42 std::bitset<N> v2 = v1; 43 assert(v1 == v2); 44 const bool greater_than_0 = std::integral_constant<bool, (N > 0)>::value; // avoid compiler warnings 45 if (greater_than_0) 46 { 47 v2[N/2].flip(); 48 assert(v1 != v2); 49 } 50 } 51 main()52int main() 53 { 54 test_equality<0>(); 55 test_equality<1>(); 56 test_equality<31>(); 57 test_equality<32>(); 58 test_equality<33>(); 59 test_equality<63>(); 60 test_equality<64>(); 61 test_equality<65>(); 62 test_equality<1000>(); 63 } 64