]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/bitset_ctor.cc
acinclude.m4 (GLIBCPP_CONFIGURE_TESTSUITE): New macro, calls...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / bitset_ctor.cc
CommitLineData
b2dad0e3
BK
1// 1999-06-08 bkoz
2
97e0a05a 3// Copyright (C) 1999, 2000 Free Software Foundation, Inc.
b2dad0e3
BK
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
17// with this library; see the file COPYING. If not, write to the Free
18// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19// USA.
20
21// 23.3.5.1 bitset constructors
22
23#include <string>
24#include <bitset>
fe413112 25#include <testsuite_hooks.h>
b2dad0e3
BK
26
27bool test01(void)
28{
29 bool test = true;
30
31 // bitset()
32 const size_t n1 = 5;
33 std::bitset<n1> bit01;
34 for (int i = 0; i < n1; ++i)
aa1b2f7d 35 VERIFY( !bit01.test(i) );
b2dad0e3
BK
36
37 // bitset(unsigned long)
38 const size_t n2 = 32;
39 unsigned long ul1 = 2;
40 std::bitset<n2> bit02(ul1);
aa1b2f7d
BV
41 VERIFY( !bit02.test(0) );
42 VERIFY( bit02.test(1) );
43 VERIFY( !bit02.test(2) );
b2dad0e3
BK
44
45 // template<_CharT, _Traits, _Alloc>
46 // explicit bitset(const basic_string<_C,_T,_A>&, size_type pos, size_type n)
47 std::string str01("stuff smith sessions");
48 const size_t n3 = 128;
49 try {
50 std::bitset<n3> bit03(str01, 5);
51 }
52 catch(std::invalid_argument& fail) {
aa1b2f7d 53 VERIFY( true );
b2dad0e3
BK
54 }
55 catch(...) {
aa1b2f7d 56 VERIFY( false );
b2dad0e3
BK
57 }
58
59 std::string str02("010101000011");
60 int sz = str02.size();
61 try {
62 std::bitset<n3> bit03(str02, 0);
63 std::string str03;
64 for (int i = 0; i < sz; ++i)
65 str03 += (bit03.test(i) ? '1' : '0');
97e0a05a 66 std::reverse(str03.begin(), str03.end());
aa1b2f7d 67 VERIFY( str03 == str02 );
b2dad0e3
BK
68 }
69 catch(std::invalid_argument& fail) {
aa1b2f7d 70 VERIFY( false );
b2dad0e3
BK
71 }
72 catch(...) {
aa1b2f7d 73 VERIFY( false );
b2dad0e3
BK
74 }
75
76
77#ifdef DEBUG_ASSERT
78 assert(test);
79#endif
80 return test;
81}
82
83int main()
84{
85 test01();
86
87 return 0;
88}