Skip to content

Commit 5408a17

Browse files
committed
Add tests with lvalue inputs
If the compiler supports forwarding references, we now test if lvalues can be used as input strings for split(), find_all(), and ifind_all(). Note that MSVC (without its recent /permissive- flag) may pass these tests without the forwarding references changes that I made, due to its non-standard binding of lvalues to rvalues.
1 parent c6f784c commit 5408a17

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

string/test/split_test.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
// See http://www.boost.org for updates, documentation, and revision history.
99

10+
#include <boost/algorithm/string/config.hpp>
11+
1012
#include <boost/algorithm/string/split.hpp>
1113
#include <boost/algorithm/string/classification.hpp>
1214
// equals predicate is used for result comparison
@@ -82,6 +84,28 @@ void iterator_test()
8284
string("xx") );
8385
deep_compare( tokens, vtokens );
8486

87+
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
88+
// If using a compiler that supports forwarding references, we should be able to use lvalues, too
89+
find_all(
90+
tokens,
91+
string("xx-abc--xx-abb"),
92+
"xx" );
93+
94+
BOOST_REQUIRE( tokens.size()==2 );
95+
BOOST_CHECK( tokens[0]==string("xx") );
96+
BOOST_CHECK( tokens[1]==string("xx") );
97+
98+
ifind_all(
99+
tokens,
100+
string("Xx-abc--xX-abb-xx"),
101+
"xx" );
102+
103+
BOOST_REQUIRE( tokens.size()==3 );
104+
BOOST_CHECK( tokens[0]==string("Xx") );
105+
BOOST_CHECK( tokens[1]==string("xX") );
106+
BOOST_CHECK( tokens[2]==string("xx") );
107+
#endif
108+
85109
// split tests
86110
split(
87111
tokens,
@@ -144,6 +168,21 @@ void iterator_test()
144168
BOOST_REQUIRE( tokens.size()==1 );
145169
BOOST_CHECK( tokens[0]==string("") );
146170

171+
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
172+
// If using a compiler that supports forwarding references, we should be able to use lvalues, too
173+
split(
174+
tokens,
175+
string("Xx-abc--xX-abb-xx"),
176+
is_any_of("xX"),
177+
token_compress_on );
178+
179+
BOOST_REQUIRE( tokens.size()==4 );
180+
BOOST_CHECK( tokens[0]==string("") );
181+
BOOST_CHECK( tokens[1]==string("-abc--") );
182+
BOOST_CHECK( tokens[2]==string("-abb-") );
183+
BOOST_CHECK( tokens[3]==string("") );
184+
#endif
185+
147186

148187
find_iterator<string::iterator> fiter=make_find_iterator(str1, first_finder("xx"));
149188
find_iterator<string::iterator> fiter2;

0 commit comments

Comments
 (0)