Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / range / test / adaptor_test / filtered_example.cpp
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 //[filtered_example
12 #include <boost/range/adaptor/filtered.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 {
30     bool operator()( int x ) const { return x % 2 == 0; }
31 };
32
33 //<-
34 void filtered_example_test()
35 //->
36 //=int main(int argc, const char* argv[])
37 {
38     using namespace boost::assign;
39     using namespace boost::adaptors;
40
41     std::vector<int> input;
42     input += 1,2,3,4,5,6,7,8,9;
43
44     boost::copy(
45         input | filtered(is_even()),
46         std::ostream_iterator<int>(std::cout, ","));
47
48 //=    return 0;
49 //=}
50 //]
51     std::vector<int> reference;
52     reference += 2,4,6,8;
53
54     std::vector<int> test;
55     boost::push_back(test, input | filtered(is_even()));
56
57     BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
58         test.begin(), test.end() );
59 }
60 }
61
62 boost::unit_test::test_suite*
63 init_unit_test_suite(int argc, char* argv[])
64 {
65     boost::unit_test::test_suite* test
66         = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.filtered_example" );
67
68     test->add( BOOST_TEST_CASE( &filtered_example_test ) );
69
70     return test;
71 }