]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/ptr_container/test/simple_test.cpp
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/ptr_vector.hpp>
13 #include <boost/shared_ptr.hpp>
14 #include <boost/lambda/lambda.hpp>
20 // A simple polymorphic class
28 Poly() : i_( cnt_
++ ) { }
30 void foo() { doFoo(); }
33 virtual void doFoo() { ++i_
; }
36 friend inline bool operator>( const Poly
& l
, const Poly r
)
45 // Normally we need something like this to compare pointers to objects
47 template< typename T
>
50 bool operator()( const boost::shared_ptr
<T
>& l
, const boost::shared_ptr
<T
>& r
) const
57 // one doesn't need to introduce new names or live with long ones
59 typedef boost::shared_ptr
<Poly
> PolyPtr
;
65 typedef vector
<PolyPtr
> vector_t
;
66 typedef boost::ptr_vector
<Poly
> ptr_vector_t
;
70 for( int i
= 0; i
< size
; ++i
)
72 svec
.push_back( PolyPtr( new Poly
) );
73 pvec
.push_back( new Poly
); // no extra syntax
76 for( int i
= 0; i
< size
; ++i
)
79 pvec
[i
].foo(); // automatic indirection
80 svec
[i
] = PolyPtr( new Poly
);
81 pvec
.replace( i
, new Poly
); // direct pointer assignment not possible, original element is deleted
84 for( vector_t::iterator i
= svec
.begin(); i
!= svec
.end(); ++i
)
87 for( ptr_vector_t::iterator i
= pvec
.begin(); i
!= pvec
.end(); ++i
)
88 i
->foo(); // automatic indirection
91 #include <boost/test/unit_test.hpp>
92 using boost::unit_test::test_suite
;
94 test_suite
* init_unit_test_suite( int argc
, char* argv
[] )
96 test_suite
* test
= BOOST_TEST_SUITE( "Pointer Container Test Suite" );
98 test
->add( BOOST_TEST_CASE( &simple_test
) );