3 // Copyright Neil Groves 2009. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
9 // For more information, see http://www.boost.org/libs/range/
11 #include <boost/range/algorithm/replace_copy.hpp>
13 #include <boost/test/test_tools.hpp>
14 #include <boost/test/unit_test.hpp>
16 #include <boost/assign.hpp>
17 #include <boost/bind.hpp>
27 template<typename Iterator
, typename Value
>
28 void test_append(Iterator target
, Value value
)
33 template< class Container
, class Value
>
34 void test_replace_copy_impl( const Container
& c
, Value to_replace
)
36 const Value replace_with
= to_replace
* 2;
38 typedef typename
boost::range_value
<Container
>::type value_type
;
39 std::vector
<value_type
> reference
;
41 typedef BOOST_DEDUCED_TYPENAME
std::vector
<value_type
>::iterator
42 iterator_t BOOST_RANGE_UNUSED
;
45 std::replace_copy(c
.begin(), c
.end(),
46 std::back_inserter(reference
), to_replace
, replace_with
),
49 std::vector
<value_type
> test
;
51 boost::replace_copy(c
, std::back_inserter(test
), to_replace
, replace_with
),
54 BOOST_CHECK_EQUAL_COLLECTIONS( reference
.begin(), reference
.end(),
55 test
.begin(), test
.end() );
57 std::vector
<value_type
> test2
;
59 boost::replace_copy(boost::make_iterator_range(c
),
60 std::back_inserter(test2
), to_replace
,
64 BOOST_CHECK_EQUAL_COLLECTIONS( reference
.begin(), reference
.end(),
65 test2
.begin(), test2
.end() );
68 template< class Container
>
69 void test_replace_copy_impl()
71 using namespace boost::assign
;
74 test_replace_copy_impl(cont
, 0);
78 test_replace_copy_impl(cont
, 0);
79 test_replace_copy_impl(cont
, 1);
83 test_replace_copy_impl(cont
, 0);
84 test_replace_copy_impl(cont
, 1);
87 cont
+= 1,2,3,4,5,6,7,8,9;
88 test_replace_copy_impl(cont
, 1);
89 test_replace_copy_impl(cont
, 9);
90 test_replace_copy_impl(cont
, 4);
93 void test_replace_copy()
95 test_replace_copy_impl
< std::vector
<int> >();
96 test_replace_copy_impl
< std::list
<int> >();
97 test_replace_copy_impl
< std::deque
<int> >();
101 boost::unit_test::test_suite
*
102 init_unit_test_suite(int argc
, char* argv
[])
104 boost::unit_test::test_suite
* test
105 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.replace_copy" );
107 test
->add( BOOST_TEST_CASE( &test_replace_copy
) );