Home | History | Annotate | Download | only in bitset.members
      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>& operator&=(const bitset<N>& rhs);
     11 
     12 #include <bitset>
     13 #include <cstdlib>
     14 #include <cassert>
     15 
     16 #include "test_macros.h"
     17 
     18 #if defined(TEST_COMPILER_CLANG)
     19 #pragma clang diagnostic ignored "-Wtautological-compare"
     20 #elif defined(TEST_COMPILER_C1XX)
     21 #pragma warning(disable: 6294) // Ill-defined for-loop:  initial condition does not satisfy test.  Loop body not executed.
     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_op_and_eq()
     36 {
     37     std::bitset<N> v1 = make_bitset<N>();
     38     std::bitset<N> v2 = make_bitset<N>();
     39     std::bitset<N> v3 = v1;
     40     v1 &= v2;
     41     for (std::size_t i = 0; i < N; ++i)
     42         assert(v1[i] == (v3[i] && v2[i]));
     43 }
     44 
     45 int main()
     46 {
     47     test_op_and_eq<0>();
     48     test_op_and_eq<1>();
     49     test_op_and_eq<31>();
     50     test_op_and_eq<32>();
     51     test_op_and_eq<33>();
     52     test_op_and_eq<63>();
     53     test_op_and_eq<64>();
     54     test_op_and_eq<65>();
     55     test_op_and_eq<1000>();
     56 }
     57