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 test(size_t pos) const; 11 12 #include <bitset> 13 #include <cstdlib> 14 #include <cassert> 15 16 #include "test_macros.h" 17 18 #if defined(TEST_COMPILER_C1XX) 19 #pragma warning(disable: 6294) // Ill-defined for-loop: initial condition does not satisfy test. Loop body not executed. 20 #endif 21 22 template <std::size_t N> 23 std::bitset<N> 24 make_bitset() 25 { 26 std::bitset<N> v; 27 for (std::size_t i = 0; i < N; ++i) 28 v[i] = static_cast<bool>(std::rand() & 1); 29 return v; 30 } 31 32 template <std::size_t N> 33 void test_test(bool test_throws) 34 { 35 const std::bitset<N> v1 = make_bitset<N>(); 36 #ifdef TEST_HAS_NO_EXCEPTIONS 37 if (test_throws) return; 38 #else 39 try 40 { 41 #endif 42 bool b = v1.test(50); 43 if (50 >= v1.size()) 44 assert(false); 45 assert(b == v1[50]); 46 assert(!test_throws); 47 #ifndef TEST_HAS_NO_EXCEPTIONS 48 } 49 catch (std::out_of_range&) 50 { 51 assert(test_throws); 52 } 53 #endif 54 } 55 56 int main() 57 { 58 test_test<0>(true); 59 test_test<1>(true); 60 test_test<31>(true); 61 test_test<32>(true); 62 test_test<33>(true); 63 test_test<63>(false); 64 test_test<64>(false); 65 test_test<65>(false); 66 test_test<1000>(false); 67 } 68