]>
Commit | Line | Data |
---|---|---|
8868286e | 1 | // { dg-options "-std=gnu++11" } |
0f0ce5ae | 2 | |
3 | // 2010-10-11 Paolo Carlini <paolo.carlini@oracle.com> | |
4 | ||
f1717362 | 5 | // Copyright (C) 2010-2016 Free Software Foundation, Inc. |
0f0ce5ae | 6 | // |
7 | // This file is part of the GNU ISO C++ Library. This library is free | |
8 | // software; you can redistribute it and/or modify it under the | |
9 | // terms of the GNU General Public License as published by the | |
10 | // Free Software Foundation; either version 3, or (at your option) | |
11 | // any later version. | |
12 | ||
13 | // This library is distributed in the hope that it will be useful, | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | ||
18 | // You should have received a copy of the GNU General Public License along | |
19 | // with this library; see the file COPYING3. If not see | |
20 | // <http://www.gnu.org/licenses/>. | |
21 | ||
22 | #include <bitset> | |
23 | #include <testsuite_hooks.h> | |
24 | ||
25 | template<std::size_t Nb, typename CharT> | |
26 | std::bitset<Nb> | |
27 | test01_ref(const CharT* str, | |
28 | typename std::basic_string<CharT>::size_type n | |
29 | = std::basic_string<CharT>::npos, | |
30 | CharT zero = CharT('0'), CharT one = CharT('1')) | |
31 | { | |
32 | return std::bitset<Nb>(n == std::basic_string<CharT>::npos | |
33 | ? std::basic_string<CharT>(str) | |
34 | : std::basic_string<CharT>(str, n), | |
35 | 0, n, zero, one); | |
36 | } | |
37 | ||
38 | // DR 1325. | |
39 | void test01() | |
40 | { | |
41 | bool test __attribute__((unused)) = true; | |
42 | using namespace std; | |
43 | ||
44 | const char s1[4] = { '0', '1', '0', '1' }; | |
45 | VERIFY( bitset<4>(s1, 4) == test01_ref<4>(s1, 4) ); | |
46 | ||
47 | const char s2[3] = { '1', '1', '0' }; | |
79eadf5c | 48 | VERIFY( bitset<6>(s2, 3) == test01_ref<6>(s2, 3) ); |
0f0ce5ae | 49 | |
50 | const char* s3 = "1110110"; | |
51 | VERIFY( bitset<7>(s3) == test01_ref<7>(s3) ); | |
52 | ||
53 | const char* s4 = "0011"; | |
54 | VERIFY( bitset<10>(s4) == test01_ref<10>(s4) ); | |
55 | ||
56 | const char* s5 = "011110000111001"; | |
57 | VERIFY( bitset<5>(s5) == test01_ref<5>(s5) ); | |
58 | ||
59 | const char* s6 = "1cc1c1"; | |
60 | VERIFY( bitset<6>(s6, basic_string<char>::npos, 'c') | |
61 | == test01_ref<6>(s6, basic_string<char>::npos, 'c') ); | |
62 | ||
63 | const char* s7 = "001011101"; | |
64 | VERIFY( bitset<9>(s7, basic_string<char>::npos, '0', '1') | |
65 | == test01_ref<9>(s7, basic_string<char>::npos, '0', '1') ); | |
66 | ||
67 | const char* s8 = "babb"; | |
68 | VERIFY( bitset<4>(s8, basic_string<char>::npos, 'a', 'b') | |
69 | == test01_ref<4>(s8, basic_string<char>::npos, 'a', 'b') ); | |
70 | ||
71 | const char* s9 = "bbabbbaaa"; | |
72 | VERIFY( bitset<100>(s9, basic_string<char>::npos, 'a', 'b') | |
73 | == test01_ref<100>(s9, basic_string<char>::npos, 'a', 'b') ); | |
74 | } | |
75 | ||
76 | int main() | |
77 | { | |
78 | test01(); | |
79 | return 0; | |
80 | } |