Skip to content

Commit 77bbc6c

Browse files
authored
Merge pull request boostorg#49 from Ben10do/feature/forwarding-references
Use forwarding references in string/split.hpp
2 parents 0a57ec3 + 45baad2 commit 77bbc6c

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

include/boost/algorithm/string/iter_find.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ namespace boost {
7171
inline SequenceSequenceT&
7272
iter_find(
7373
SequenceSequenceT& Result,
74+
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
75+
RangeT&& Input,
76+
#else
7477
RangeT& Input,
78+
#endif
7579
FinderT Finder )
7680
{
7781
BOOST_CONCEPT_ASSERT((
@@ -142,7 +146,11 @@ namespace boost {
142146
inline SequenceSequenceT&
143147
iter_split(
144148
SequenceSequenceT& Result,
149+
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
150+
RangeT&& Input,
151+
#else
145152
RangeT& Input,
153+
#endif
146154
FinderT Finder )
147155
{
148156
BOOST_CONCEPT_ASSERT((

include/boost/algorithm/string/split.hpp

+12
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ namespace boost {
6161
template< typename SequenceSequenceT, typename Range1T, typename Range2T >
6262
inline SequenceSequenceT& find_all(
6363
SequenceSequenceT& Result,
64+
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
65+
Range1T&& Input,
66+
#else
6467
Range1T& Input,
68+
#endif
6569
const Range2T& Search)
6670
{
6771
return ::boost::algorithm::iter_find(
@@ -96,7 +100,11 @@ namespace boost {
96100
template< typename SequenceSequenceT, typename Range1T, typename Range2T >
97101
inline SequenceSequenceT& ifind_all(
98102
SequenceSequenceT& Result,
103+
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
104+
Range1T&& Input,
105+
#else
99106
Range1T& Input,
107+
#endif
100108
const Range2T& Search,
101109
const std::locale& Loc=std::locale() )
102110
{
@@ -139,7 +147,11 @@ namespace boost {
139147
template< typename SequenceSequenceT, typename RangeT, typename PredicateT >
140148
inline SequenceSequenceT& split(
141149
SequenceSequenceT& Result,
150+
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
151+
RangeT&& Input,
152+
#else
142153
RangeT& Input,
154+
#endif
143155
PredicateT Pred,
144156
token_compress_mode_type eCompress=token_compress_off )
145157
{

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 rvalues, 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 rvalues, 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)