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
18#pragma clang diagnostic ignored "-Wtautological-compare"
19
20template <std::size_t N>
21void test_char_pointer_ctor()
22{
23    {
24    try
25    {
26        std::bitset<N> v("xxx1010101010xxxx");
27        assert(false);
28    }
29    catch (std::invalid_argument&)
30    {
31    }
32    }
33
34    {
35    const char str[] ="1010101010";
36    std::bitset<N> v(str);
37    std::size_t M = std::min<std::size_t>(N, 10);
38    for (std::size_t i = 0; i < M; ++i)
39        assert(v[i] == (str[M - 1 - i] == '1'));
40    for (std::size_t i = 10; i < N; ++i)
41        assert(v[i] == false);
42    }
43}
44
45int main()
46{
47    test_char_pointer_ctor<0>();
48    test_char_pointer_ctor<1>();
49    test_char_pointer_ctor<31>();
50    test_char_pointer_ctor<32>();
51    test_char_pointer_ctor<33>();
52    test_char_pointer_ctor<63>();
53    test_char_pointer_ctor<64>();
54    test_char_pointer_ctor<65>();
55    test_char_pointer_ctor<1000>();
56}
57