bfa533fd0652b51ad01314438f0fd7eb6edb8e91
[platform/upstream/boost.git] / libs / range / test / adaptor_test / map_values_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 //[map_values_example
12 #include <boost/range/adaptor/map.hpp>
13 #include <boost/range/algorithm/copy.hpp>
14 #include <boost/assign.hpp>
15 #include <iterator>
16 #include <iostream>
17 #include <map>
18 #include <vector>
19
20 //<-
21 #include <boost/test/test_tools.hpp>
22 #include <boost/test/unit_test.hpp>
23
24 #include <boost/range/algorithm_ext/push_back.hpp>
25
26 namespace 
27 {
28 void map_values_example_test()
29 //->
30 //=int main(int argc, const char* argv[])
31 {
32     using namespace boost::assign;
33     using namespace boost::adaptors;
34
35     std::map<int,int> input;
36     for (int i = 0; i < 10; ++i)
37         input.insert(std::make_pair(i, i * 10));
38
39     boost::copy(
40         input | map_values,
41         std::ostream_iterator<int>(std::cout, ","));
42
43 //=    return 0;
44 //=}
45 //]
46     std::vector<int> reference;
47     reference += 0,10,20,30,40,50,60,70,80,90;
48
49     std::vector<int> test;
50     boost::push_back(test, input | map_values);
51
52     BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
53         test.begin(), test.end() );
54 }
55 }
56
57 boost::unit_test::test_suite*
58 init_unit_test_suite(int argc, char* argv[])
59 {
60     boost::unit_test::test_suite* test
61         = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.map_values_example" );
62
63     test->add( BOOST_TEST_CASE( &map_values_example_test ) );
64
65     return test;
66 }