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