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