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 "test_data.hpp"
13 #include <boost/ptr_container/exception.hpp>
14 #include <boost/range/sub_range.hpp>
16 template< typename C, typename B, typename T, bool Ordered >
19 template< class T, bool Ordered >
20 struct test_algorithms
22 template< class Cont >
23 void operator()( Cont& c, const Cont& c2 ) const
25 typename Cont::iterator i;
26 typename Cont::const_iterator ci;
29 i = c.lower_bound( *t );
30 ci = c2.lower_bound( *t );
31 i = c.upper_bound( *t );
32 ci = c2.upper_bound( *t );
35 BOOST_DEDUCED_TYPENAME Cont::reverse_iterator ri = c.rbegin();
36 BOOST_DEDUCED_TYPENAME Cont::const_reverse_iterator cri = c2.rbegin();
37 BOOST_DEDUCED_TYPENAME Cont::reverse_iterator rv2 = c.rend();
38 BOOST_DEDUCED_TYPENAME Cont::const_reverse_iterator cvr2 = c2.rend();
45 struct test_algorithms<T,false>
48 void operator()( Cont& c, const Cont& c2 ) const
53 template< typename C, typename B, typename T, bool Ordered >
56 using namespace boost;
58 BOOST_TEST_MESSAGE( "starting associative container test" );
59 enum { max_cnt = 10, size = 100 };
61 BOOST_CHECK( c.size() == 0 );
62 c.insert( c.end(), new T );
63 c.insert( c.end(), new T );
65 const C c2( c.begin(), c.end() );
66 BOOST_CHECK( c.size() == c2.size() );
70 BOOST_TEST_MESSAGE( "finished construction test" );
73 BOOST_CHECK_EQUAL( a_copy.size(), c.size() );
75 BOOST_CHECK_EQUAL( a_copy.size(), c.size() );
79 BOOST_CHECK( a_copy.empty() );
81 BOOST_TEST_MESSAGE( "finished copying test" );
83 BOOST_DEDUCED_TYPENAME C::allocator_type alloc = c.get_allocator();
84 BOOST_DEDUCED_TYPENAME C::iterator i = c.begin();
85 BOOST_DEDUCED_TYPENAME C::const_iterator ci = c2.begin();
88 BOOST_DEDUCED_TYPENAME C::iterator i2 = c.end();
89 BOOST_DEDUCED_TYPENAME C::const_iterator ci2 = c2.begin();
91 BOOST_TEST_MESSAGE( "finished iterator test" );
93 BOOST_DEDUCED_TYPENAME C::size_type s = c.size();
94 BOOST_DEDUCED_TYPENAME C::size_type s2 = c.max_size();
96 BOOST_CHECK_EQUAL( c.size(), s );
99 BOOST_TEST_MESSAGE( "finished accessors test" );
102 c.insert( c.end(), t );
103 c.insert( c.end(), std::auto_ptr<T>( new T ) );
105 std::auto_ptr<T> ap( new T );
107 c3.insert( c.begin(), c.end() );
108 c.erase( c.begin() );
109 c3.erase( c3.begin(), c3.end() );
115 BOOST_CHECK( c3.empty() );
117 BOOST_CHECK( !c3.empty() );
118 BOOST_CHECK( c.empty() );
122 // remark: we cannot pass c3 directly as it would
123 // extract const iterators ... and the
124 // current standard does not allow erase()
125 // to be given const iterators
127 c3.erase( boost::make_iterator_range(c3) );
128 BOOST_CHECK( c3.empty() );
129 BOOST_TEST_MESSAGE( "finished modifiers test" );
131 c.insert( c.end(), new T );
132 typename C::auto_type ptr2 = c.release( c.begin() );
133 std::auto_ptr<C> ap2 = c.release();
135 BOOST_TEST_MESSAGE( "finished release/clone test" );
139 BOOST_CHECK_EQUAL( c3.size(), 2u );
140 #if defined(BOOST_NO_SFINAE) || defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
142 c3.insert( make_iterator_range( c ) );
143 // BOOST_CHECK_EQUAL( c3.size(), 4u );
145 c. BOOST_NESTED_TEMPLATE transfer<C>( c3.begin(), c3 );
146 BOOST_CHECK( c3.empty() == false );
148 unsigned long c3size = c3.size();
149 hide_warning( c3size );
150 unsigned long num = c. BOOST_NESTED_TEMPLATE transfer<C>( c3.begin(),
154 BOOST_CHECK( num > 0 );
155 BOOST_CHECK_EQUAL( num, c.size() );
156 BOOST_CHECK( c3.empty() );
157 BOOST_CHECK( !c.empty() );
158 c3. BOOST_NESTED_TEMPLATE transfer<C>( c );
159 BOOST_CHECK( !c3.empty() );
160 BOOST_CHECK( c.empty() );
161 #ifdef BOOST_NO_SFINAE
163 c. BOOST_NESTED_TEMPLATE transfer<C>( make_iterator_range( c3 ), c3 );
164 BOOST_CHECK( !c.empty() );
165 BOOST_CHECK( c3.empty() );
168 BOOST_TEST_MESSAGE( "finished transfer test" );
173 BOOST_TEST_MESSAGE( "finished set/map interface test" );
176 sub_range<const C> csub;
183 test_algorithms<T,Ordered>()( c, c2 );
184 sub = c.equal_range( *t );
185 csub = c2.equal_range( *t );
188 BOOST_TEST_MESSAGE( "finished algorithms interface test" );