]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/assign/test/my_vector_example.cpp
1 // Boost.Assign library
3 // Copyright Thorsten Ottosen 2003-2004. 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)
8 // For more information, see http://www.boost.org/libs/assign/
12 #include <boost/detail/workaround.hpp>
14 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
15 # pragma warn -8091 // suppress warning in Boost.Test
16 # pragma warn -8057 // unused argument argc/argv in Boost.Test
19 #include <boost/assign/list_inserter.hpp>
20 #include <boost/test/test_tools.hpp>
21 #include <boost/function.hpp>
22 #include <boost/bind.hpp>
26 namespace ba
= boost::assign
;
33 typedef typename
C::iterator iterator
;
36 range_inserter( C
& c
)
37 : begin( c
.begin() ), end( c
.end() )
41 void operator()( T r
)
44 throw std::range_error( "range error: <range_inserter>" );
53 inline range_inserter
<C
> make_range_inserter( C
& c
)
55 return range_inserter
<C
>( c
);
63 typedef std::vector
<T
> vector_t
;
64 typedef typename
vector_t::size_type size_type
;
68 my_vector() : data_( 10, 0 )
71 ba::list_inserter
< range_inserter
< vector_t
>, T
>
74 return ba::make_list_inserter( make_range_inserter( data_
) )( r
);
77 size_type
size() const
82 const T
& operator[]( size_type index
)
84 return data_
.at( index
);
90 void check_list_inserter()
93 using namespace boost::assign
;
96 vec
= 1,2,3,4,5,6,7,8,9,10;
97 BOOST_CHECK_EQUAL( vec
.size(), 10u );
98 BOOST_CHECK_EQUAL( vec
[0], 1 );
99 BOOST_CHECK_EQUAL( vec
[9], 10 );
104 #include <boost/test/unit_test.hpp>
105 using boost::unit_test::test_suite
;
107 test_suite
* init_unit_test_suite( int argc
, char* argv
[] )
109 test_suite
* test
= BOOST_TEST_SUITE( "List Test Suite" );
111 test
->add( BOOST_TEST_CASE( &check_list_inserter
) );