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/indirected.hpp>
13
#include <boost/test/test_tools.hpp>
14
#include <boost/test/unit_test.hpp>
16
#include <boost/assign.hpp>
17
#include <boost/shared_ptr.hpp>
18
#include <boost/range/algorithm_ext.hpp>
30
template< class Container >
31
void indirected_test_impl( Container& c )
33
using namespace boost::adaptors;
35
// This is my preferred syntax using the | operator.
36
std::vector< int > test_result1;
37
boost::push_back(test_result1, c | indirected);
39
// This is an alternative syntax preferred by some.
40
std::vector< int > test_result2;
41
boost::push_back(test_result2, adaptors::indirect(c));
43
// Calculate the reference result.
44
std::vector< int > reference_result;
45
typedef BOOST_DEDUCED_TYPENAME Container::const_iterator iter_t;
46
for (iter_t it = c.begin(); it != c.end(); ++it)
48
reference_result.push_back(**it);
51
BOOST_CHECK_EQUAL_COLLECTIONS( reference_result.begin(),
52
reference_result.end(),
56
BOOST_CHECK_EQUAL_COLLECTIONS( reference_result.begin(),
57
reference_result.end(),
62
template< class Container >
63
void indirected_test_impl()
65
using namespace boost::assign;
69
indirected_test_impl(c);
71
c += boost::shared_ptr<int>(new int(1));
72
indirected_test_impl(c);
75
v += 1,1,2,2,2,3,4,4,4,4,5,6,7,8,9,9;
76
for (std::vector<int>::const_iterator it = v.begin(); it != v.end(); ++it)
78
c += boost::shared_ptr<int>(new int(*it));
80
indirected_test_impl(c);
83
void indirected_test()
85
indirected_test_impl< std::vector< boost::shared_ptr< int > > >();
90
boost::unit_test::test_suite*
91
init_unit_test_suite(int argc, char* argv[])
93
boost::unit_test::test_suite* test
94
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.indirected" );
96
test->add( BOOST_TEST_CASE( &boost::indirected_test ) );