| 1 | // Boost.Assign library |
| 2 | // |
| 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) |
| 7 | // |
| 8 | // For more information, see http://www.boost.org/libs/assign/ |
| 9 | // |
| 10 | |
| 11 | |
| 12 | #include <boost/detail/workaround.hpp> |
| 13 | |
| 14 | #if BOOST_WORKAROUND(BOOST_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 |
| 17 | #endif |
| 18 | |
| 19 | #include <boost/assign/ptr_list_of.hpp> |
| 20 | #include <boost/test/test_tools.hpp> |
| 21 | #include <boost/ptr_container/ptr_container.hpp> |
| 22 | |
| 23 | struct Foo |
| 24 | { |
| 25 | int i; |
| 26 | |
| 27 | Foo() : i(0) |
| 28 | { } |
| 29 | Foo( int i ) : i(i) |
| 30 | { } |
| 31 | Foo( int i, int ) : i(i) |
| 32 | { } |
| 33 | Foo( const char*, int i, int ) : i(i) |
| 34 | { } |
| 35 | }; |
| 36 | |
| 37 | inline bool operator<( Foo l, Foo r ) |
| 38 | { |
| 39 | return l.i < r.i; |
| 40 | } |
| 41 | |
| 42 | template< class PtrCont > |
| 43 | void check_ptr_list_of_impl() |
| 44 | { |
| 45 | using namespace std; |
| 46 | using namespace boost; |
| 47 | using namespace boost::assign; |
| 48 | |
| 49 | PtrCont deq; |
| 50 | deq = ptr_list_of<Foo>( us: 42 )()()( 3, 3 )( "foo" , 2, 1 ); |
| 51 | BOOST_CHECK( deq.size() == 5 ); |
| 52 | |
| 53 | } |
| 54 | |
| 55 | void check_ptr_list_of() |
| 56 | { |
| 57 | check_ptr_list_of_impl< boost::ptr_deque<Foo> >(); |
| 58 | check_ptr_list_of_impl< boost::ptr_list<Foo> >(); |
| 59 | check_ptr_list_of_impl< boost::ptr_vector<Foo> >(); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | #include <boost/test/unit_test.hpp> |
| 64 | using boost::unit_test::test_suite; |
| 65 | |
| 66 | test_suite* init_unit_test_suite( int argc, char* argv[] ) |
| 67 | { |
| 68 | test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); |
| 69 | |
| 70 | test->add( BOOST_TEST_CASE( &check_ptr_list_of ) ); |
| 71 | |
| 72 | return test; |
| 73 | } |
| 74 | |
| 75 | |
| 76 | |