]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/range/test/adaptor_test/map.cpp
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/adaptor/map.hpp>
13 #include <boost/test/test_tools.hpp>
14 #include <boost/test/unit_test.hpp>
16 #include <boost/array.hpp>
17 #include <boost/assign.hpp>
18 #include <boost/range/algorithm_ext.hpp>
28 template< class Container
>
29 void map_test_keys( Container
& c
)
31 using namespace boost::adaptors
;
33 std::vector
<int> keys
;
34 boost::push_back(keys
, c
| map_keys
);
36 std::vector
<int> keys2
;
37 boost::push_back(keys2
, adaptors::keys(c
));
39 std::vector
<int> reference_keys
;
40 typedef BOOST_DEDUCED_TYPENAME
Container::const_iterator iter_t
;
41 for (iter_t it
= c
.begin(); it
!= c
.end(); ++it
)
43 reference_keys
.push_back(it
->first
);
46 BOOST_CHECK_EQUAL_COLLECTIONS( reference_keys
.begin(),
51 BOOST_CHECK_EQUAL_COLLECTIONS( reference_keys
.begin(),
57 template< class Container
>
58 void map_test_values( Container
& c
)
60 using namespace boost::adaptors
;
62 std::vector
<int> values
;
63 boost::push_back(values
, c
| map_values
);
65 std::vector
<int> values2
;
66 boost::push_back(values2
, adaptors::values(c
));
68 std::vector
<int> reference_values
;
69 typedef BOOST_DEDUCED_TYPENAME
Container::const_iterator iter_t
;
70 for (iter_t it
= c
.begin(); it
!= c
.end(); ++it
)
72 reference_values
.push_back(it
->second
);
75 BOOST_CHECK_EQUAL_COLLECTIONS( reference_values
.begin(),
76 reference_values
.end(),
80 BOOST_CHECK_EQUAL_COLLECTIONS( reference_values
.begin(),
81 reference_values
.end(),
86 template< class Container
>
89 using namespace boost::assign
;
98 c
.insert(std::make_pair(1,2));
102 // Test many elements
103 for (int x
= 2; x
< 10; ++x
)
105 c
.insert(std::make_pair(x
, x
* 2));
113 map_test_impl
< std::map
<int,int> >();
116 void test_trac_item_4388()
118 typedef std::pair
<int,char> pair_t
;
119 const boost::array
<pair_t
,3> ar
= {{
125 const boost::array
<int, 3> expected_keys
= {{ 3, 1, 4 }};
126 const boost::array
<char, 3> expected_values
= {{ 'a', 'b', 'c' }};
129 std::vector
<int> test
;
130 boost::push_back(test
, ar
| boost::adaptors::map_keys
);
131 BOOST_CHECK_EQUAL_COLLECTIONS(
132 expected_keys
.begin(), expected_keys
.end(),
133 test
.begin(), test
.end()
138 std::vector
<char> test
;
139 boost::push_back(test
, ar
| boost::adaptors::map_values
);
140 BOOST_CHECK_EQUAL_COLLECTIONS(
141 expected_values
.begin(), expected_values
.end(),
142 test
.begin(), test
.end()
147 std::vector
<char> test
;
148 boost::array
<std::pair
<int, char>, 3> src(ar
);
149 boost::push_back(test
, src
| boost::adaptors::map_values
);
150 BOOST_CHECK_EQUAL_COLLECTIONS(
151 expected_values
.begin(), expected_values
.end(),
152 test
.begin(), test
.end()
161 boost::unit_test::test_suite
*
162 init_unit_test_suite(int argc
, char* argv
[])
164 boost::unit_test::test_suite
* test
165 = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.map" );
167 test
->add( BOOST_TEST_CASE( &boost::map_test
) );
168 test
->add( BOOST_TEST_CASE( &boost::test_trac_item_4388
) );