]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/ptr_container/test/indirect_fun.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / ptr_container / test / indirect_fun.cpp
1 //
2 // Boost.Pointer Container
3 //
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)
8 //
9 // For more information, see http://www.boost.org/libs/ptr_container/
10 //
11
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>
16 #include <algorithm>
17 #include <functional>
18 #include <string>
19
20 bool lesser_than( const std::string& l, const std::string& r )
21 {
22 return l < r;
23 }
24
25
26 void test_fun()
27 {
28 using namespace boost;
29 ptr_vector<std::string> vec;
30
31 indirect_fun< std::less<std::string> > fun;
32
33 std::string* ptr1 = new std::string("bar");
34 std::string* ptr2 = new std::string("foo");
35 BOOST_CHECK( fun( ptr1, ptr2 ) == true );
36
37 void* vptr1 = ptr1;
38 void* vptr2 = ptr2;
39
40 void_ptr_indirect_fun< std::less<std::string>, std::string> cast_fun;
41 BOOST_CHECK( cast_fun( vptr1, vptr2 ) == true );
42
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") );
48
49 std::sort( vec.begin().base(), vec.end().base(), cast_fun );
50 BOOST_CHECK( vec[0] == "a" );
51 BOOST_CHECK( vec[4] == "dd" );
52
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" );
57
58 void* iptr1 = new int(2);
59 void* iptr2 = new int(3);
60
61 void_ptr_indirect_fun<std::less<int>, int> int_cast_fun;
62 BOOST_CHECK( int_cast_fun(iptr1,iptr2) );
63
64 }
65
66 #include <boost/test/unit_test.hpp>
67 using boost::unit_test::test_suite;
68
69 test_suite* init_unit_test_suite( int argc, char* argv[] )
70 {
71 test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" );
72
73 test->add( BOOST_TEST_CASE( &test_fun ) );
74
75 return test;
76 }
77
78