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 // template <class charT> 11 // explicit bitset(const charT* str, 12 // typename basic_string<charT>::size_type n = basic_string<charT>::npos, 13 // charT zero = charT('0'), charT one = charT('1')); 14 15 #include <bitset> 16 #include <cassert> 17 #include <algorithm> // for 'min' and 'max' 18 #include <stdexcept> // for 'invalid_argument' 19 20 #include "test_macros.h" 21 22 template <std::size_t N> test_char_pointer_ctor()23void test_char_pointer_ctor() 24 { 25 { 26 #ifndef TEST_HAS_NO_EXCEPTIONS 27 try { 28 std::bitset<N> v("xxx1010101010xxxx"); 29 assert(false); 30 } 31 catch (std::invalid_argument&) {} 32 #endif 33 } 34 35 { 36 const char str[] ="1010101010"; 37 std::bitset<N> v(str); 38 std::size_t M = std::min<std::size_t>(N, 10); 39 for (std::size_t i = 0; i < M; ++i) 40 assert(v[i] == (str[M - 1 - i] == '1')); 41 for (std::size_t i = 10; i < N; ++i) 42 assert(v[i] == false); 43 } 44 } 45 main()46int main() 47 { 48 test_char_pointer_ctor<0>(); 49 test_char_pointer_ctor<1>(); 50 test_char_pointer_ctor<31>(); 51 test_char_pointer_ctor<32>(); 52 test_char_pointer_ctor<33>(); 53 test_char_pointer_ctor<63>(); 54 test_char_pointer_ctor<64>(); 55 test_char_pointer_ctor<65>(); 56 test_char_pointer_ctor<1000>(); 57 } 58