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