1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // template <class charT> 10 // explicit bitset(const charT* str, 11 // typename basic_string<charT>::size_type n = basic_string<charT>::npos, 12 // charT zero = charT('0'), charT one = charT('1')); 13 14 #include <bitset> 15 #include <cassert> 16 #include <algorithm> // for 'min' and 'max' 17 #include <stdexcept> // for 'invalid_argument' 18 19 #include "test_macros.h" 20 21 #ifdef TEST_COMPILER_MSVC 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 void test_char_pointer_ctor() 27 { 28 { 29 #ifndef TEST_HAS_NO_EXCEPTIONS 30 try { 31 std::bitset<N> v("xxx1010101010xxxx"); 32 assert(false); 33 } 34 catch (std::invalid_argument&) {} 35 #endif 36 } 37 38 { 39 const char str[] = "1010101010"; 40 std::bitset<N> v(str); 41 std::size_t M = std::min<std::size_t>(v.size(), 10); 42 for (std::size_t i = 0; i < M; ++i) 43 assert(v[i] == (str[M - 1 - i] == '1')); 44 for (std::size_t i = 10; i < v.size(); ++i) 45 assert(v[i] == false); 46 } 47 } 48 49 int main(int, char**) 50 { 51 test_char_pointer_ctor<0>(); 52 test_char_pointer_ctor<1>(); 53 test_char_pointer_ctor<31>(); 54 test_char_pointer_ctor<32>(); 55 test_char_pointer_ctor<33>(); 56 test_char_pointer_ctor<63>(); 57 test_char_pointer_ctor<64>(); 58 test_char_pointer_ctor<65>(); 59 test_char_pointer_ctor<1000>(); 60 61 return 0; 62 } 63