• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #if defined(TEST_COMPILER_C1XX)
23 #pragma warning(disable: 6294) // Ill-defined for-loop:  initial condition does not satisfy test.  Loop body not executed.
24 #endif
25 
26 template <std::size_t N>
test_char_pointer_ctor()27 void test_char_pointer_ctor()
28 {
29     {
30 #ifndef TEST_HAS_NO_EXCEPTIONS
31         try {
32             std::bitset<N> v("xxx1010101010xxxx");
33             assert(false);
34         }
35         catch (std::invalid_argument&) {}
36 #endif
37     }
38 
39     {
40     const char str[] ="1010101010";
41     std::bitset<N> v(str);
42     std::size_t M = std::min<std::size_t>(N, 10);
43     for (std::size_t i = 0; i < M; ++i)
44         assert(v[i] == (str[M - 1 - i] == '1'));
45     for (std::size_t i = 10; i < N; ++i)
46         assert(v[i] == false);
47     }
48 }
49 
main()50 int main()
51 {
52     test_char_pointer_ctor<0>();
53     test_char_pointer_ctor<1>();
54     test_char_pointer_ctor<31>();
55     test_char_pointer_ctor<32>();
56     test_char_pointer_ctor<33>();
57     test_char_pointer_ctor<63>();
58     test_char_pointer_ctor<64>();
59     test_char_pointer_ctor<65>();
60     test_char_pointer_ctor<1000>();
61 }
62