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