• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Range library
2 //
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)
7 //
8 //
9 // For more information, see http://www.boost.org/libs/range/
10 //
11 //[replaced_if_example
12 #include <boost/range/adaptor/replaced_if.hpp>
13 #include <boost/range/algorithm/copy.hpp>
14 #include <boost/assign.hpp>
15 #include <iterator>
16 #include <iostream>
17 #include <vector>
18 
19 //<-
20 #include <boost/test/test_tools.hpp>
21 #include <boost/test/unit_test.hpp>
22 
23 #include <boost/range/algorithm_ext/push_back.hpp>
24 
25 namespace
26 {
27 //->
28 struct is_even
29 {
operator ()__anond08296a10111::is_even30     bool operator()(int x) const { return x % 2 == 0; }
31 };
32 
33 //<-
replaced_if_example_test()34 void replaced_if_example_test()
35 //->
36 //=int main(int argc, const char* argv[])
37 {
38     using namespace boost::adaptors;
39     using namespace boost::assign;
40 
41     std::vector<int> input;
42     input += 1,2,3,4,5,6,7,8,9;
43 
44     boost::copy(
45         input | replaced_if(is_even(), 10),
46         std::ostream_iterator<int>(std::cout, ","));
47 
48 //=    return 0;
49 //=}
50 //]
51     std::vector<int> reference;
52     reference += 1,10,3,10,5,10,7,10,9;
53 
54     std::vector<int> test;
55     boost::push_back(test, input | replaced_if(is_even(), 10));
56 
57     BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
58         test.begin(), test.end() );
59 }
60 }
61 
62 boost::unit_test::test_suite*
init_unit_test_suite(int argc,char * argv[])63 init_unit_test_suite(int argc, char* argv[])
64 {
65     boost::unit_test::test_suite* test
66         = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.replaced_if_example" );
67 
68     test->add( BOOST_TEST_CASE( &replaced_if_example_test ) );
69 
70     return test;
71 }
72