]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/range/test/algorithm_test/generate.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/algorithm/generate.hpp>
13 #include <boost/test/test_tools.hpp>
14 #include <boost/test/unit_test.hpp>
16 #include <boost/assign.hpp>
31 typedef int result_type
;
33 generator_fn() : m_count(0) {}
34 int operator()() { return ++m_count
; }
40 template< class Container
>
41 void test_generate_impl(Container
& cont
)
43 Container
reference(cont
);
44 std::generate(reference
.begin(), reference
.end(), generator_fn());
47 boost::generate(test
, generator_fn());
49 BOOST_CHECK_EQUAL_COLLECTIONS( reference
.begin(), reference
.end(),
50 test
.begin(), test
.end() );
52 Container
test2(cont
);
53 boost::generate(boost::make_iterator_range(test2
), generator_fn());
55 BOOST_CHECK_EQUAL_COLLECTIONS( reference
.begin(), reference
.end(),
56 test2
.begin(), test2
.end() );
59 template< class Container
>
60 void test_generate_impl()
62 using namespace boost::assign
;
65 test_generate_impl(cont
);
69 test_generate_impl(cont
);
72 cont
+= 9,8,7,6,5,4,3,2,1;
73 test_generate_impl(cont
);
78 test_generate_impl
< std::vector
<int> >();
79 test_generate_impl
< std::list
<int> >();
80 test_generate_impl
< std::deque
<int> >();
86 boost::unit_test::test_suite
*
87 init_unit_test_suite(int argc
, char* argv
[])
89 boost::unit_test::test_suite
* test
90 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.generate" );
92 test
->add( BOOST_TEST_CASE( &boost::test_generate
) );