9
9
// test bitset(string, pos, n, zero, one);
10
10
11
11
#include < bitset>
12
- #include < cassert>
13
12
#include < algorithm> // for 'min' and 'max'
13
+ #include < cassert>
14
14
#include < stdexcept> // for 'invalid_argument'
15
+ #include < string>
15
16
16
17
#include " test_macros.h"
17
18
18
- #if defined(TEST_COMPILER_C1XX)
19
- #pragma warning(disable: 6294) // Ill-defined for-loop: initial condition does not satisfy test. Loop body not executed.
20
- #endif
21
-
22
19
template <std::size_t N>
23
- void test_string_ctor ()
24
- {
20
+ void test_string_ctor () {
25
21
#ifndef TEST_HAS_NO_EXCEPTIONS
26
22
{
27
23
try {
28
- std::string str (" xxx1010101010xxxx" );
29
- std::bitset<N> v (str, str .size ()+1 , 10 );
24
+ std::string s (" xxx1010101010xxxx" );
25
+ std::bitset<N> v (s, s .size ()+1 , 10 );
30
26
assert (false );
31
27
}
32
28
catch (std::out_of_range&)
@@ -35,8 +31,8 @@ void test_string_ctor()
35
31
}
36
32
{
37
33
try {
38
- std::string str (" xxx1010101010xxxx" );
39
- std::bitset<N> v (str , 2 , 10 );
34
+ std::string s (" xxx1010101010xxxx" );
35
+ std::bitset<N> v (s , 2 , 10 );
40
36
assert (false );
41
37
}
42
38
catch (std::invalid_argument&)
@@ -45,8 +41,8 @@ void test_string_ctor()
45
41
}
46
42
{
47
43
try {
48
- std::string str (" xxxbababababaxxxx" );
49
- std::bitset<N> v (str , 2 , 10 , ' a' , ' b' );
44
+ std::string s (" xxxbababababaxxxx" );
45
+ std::bitset<N> v (s , 2 , 10 , ' a' , ' b' );
50
46
assert (false );
51
47
}
52
48
catch (std::invalid_argument&)
@@ -55,21 +51,21 @@ void test_string_ctor()
55
51
}
56
52
#endif // TEST_HAS_NO_EXCEPTIONS
57
53
{
58
- std::string str (" xxx1010101010xxxx" );
59
- std::bitset<N> v (str , 3 , 10 );
60
- std::size_t M = std::min<std::size_t >(N , 10 );
54
+ std::string s (" xxx1010101010xxxx" );
55
+ std::bitset<N> v (s , 3 , 10 );
56
+ std::size_t M = std::min<std::size_t >(v. size () , 10 );
61
57
for (std::size_t i = 0 ; i < M; ++i)
62
- assert (v[i] == (str [3 + M - 1 - i] == ' 1' ));
63
- for (std::size_t i = 10 ; i < N ; ++i)
58
+ assert (v[i] == (s [3 + M - 1 - i] == ' 1' ));
59
+ for (std::size_t i = 10 ; i < v. size () ; ++i)
64
60
assert (v[i] == false );
65
61
}
66
62
{
67
- std::string str (" xxxbababababaxxxx" );
68
- std::bitset<N> v (str , 3 , 10 , ' a' , ' b' );
69
- std::size_t M = std::min<std::size_t >(N , 10 );
63
+ std::string s (" xxxbababababaxxxx" );
64
+ std::bitset<N> v (s , 3 , 10 , ' a' , ' b' );
65
+ std::size_t M = std::min<std::size_t >(v. size () , 10 );
70
66
for (std::size_t i = 0 ; i < M; ++i)
71
- assert (v[i] == (str [3 + M - 1 - i] == ' b' ));
72
- for (std::size_t i = 10 ; i < N ; ++i)
67
+ assert (v[i] == (s [3 + M - 1 - i] == ' b' ));
68
+ for (std::size_t i = 10 ; i < v. size () ; ++i)
73
69
assert (v[i] == false );
74
70
}
75
71
}
@@ -86,8 +82,7 @@ void test_for_non_eager_instantiation() {
86
82
static_assert (!std::is_constructible<std::bitset<3 >, Nonsense*, size_t , Nonsense&, Nonsense&>::value, " " );
87
83
}
88
84
89
- int main (int , char **)
90
- {
85
+ int main (int , char **) {
91
86
test_string_ctor<0 >();
92
87
test_string_ctor<1 >();
93
88
test_string_ctor<31 >();
@@ -99,5 +94,5 @@ int main(int, char**)
99
94
test_string_ctor<1000 >();
100
95
test_for_non_eager_instantiation ();
101
96
102
- return 0 ;
97
+ return 0 ;
103
98
}
0 commit comments