2 // Boost.Pointer Container
4 // Copyright Thorsten Ottosen 2003-2005. Use, modification and
5 // distribution is subject to the Boost Software License, Version
6 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // For more information, see http://www.boost.org/libs/ptr_container/
12 #include <boost/ptr_container/indirect_fun.hpp>
13 #include <boost/ptr_container/ptr_vector.hpp>
14 #include <boost/assign/list_inserter.hpp>
15 #include <boost/test/test_tools.hpp>
20 bool lesser_than( const std::string
& l
, const std::string
& r
)
28 using namespace boost
;
29 ptr_vector
<std::string
> vec
;
31 indirect_fun
< std::less
<std::string
> > fun
;
33 std::string
* ptr1
= new std::string("bar");
34 std::string
* ptr2
= new std::string("foo");
35 BOOST_CHECK( fun( ptr1
, ptr2
) == true );
40 void_ptr_indirect_fun
< std::less
<std::string
>, std::string
> cast_fun
;
41 BOOST_CHECK( cast_fun( vptr1
, vptr2
) == true );
43 assign::push_back( vec
)( new std::string("aa") )
44 ( new std::string("bb") )
45 ( new std::string("dd") )
46 ( new std::string("cc") )
47 ( new std::string("a") );
49 std::sort( vec
.begin().base(), vec
.end().base(), cast_fun
);
50 BOOST_CHECK( vec
[0] == "a" );
51 BOOST_CHECK( vec
[4] == "dd" );
53 std::sort( vec
.begin().base(), vec
.end().base(),
54 make_void_ptr_indirect_fun
<std::string
>( &lesser_than
) );
55 BOOST_CHECK( vec
[1] == "aa" );
56 BOOST_CHECK( vec
[2] == "bb" );
58 void* iptr1
= new int(2);
59 void* iptr2
= new int(3);
61 void_ptr_indirect_fun
<std::less
<int>, int> int_cast_fun
;
62 BOOST_CHECK( int_cast_fun(iptr1
,iptr2
) );
66 #include <boost/test/unit_test.hpp>
67 using boost::unit_test::test_suite
;
69 test_suite
* init_unit_test_suite( int argc
, char* argv
[] )
71 test_suite
* test
= BOOST_TEST_SUITE( "Pointer Container Test Suite" );
73 test
->add( BOOST_TEST_CASE( &test_fun
) );