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/test/unit_test.hpp>
13 #include "associative_test_data.hpp"
14 #include <boost/ptr_container/ptr_unordered_set.hpp>
15 #include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp>
17 template< class SetDerived
, class SetBase
, class T
>
24 transfer_test( from
, to
);
27 template< class BaseContainer
, class DerivedContainer
, class Derived
>
30 DerivedContainer derived
;
31 derived
.insert( new Derived
);
32 derived
.insert( new Derived
);
34 BaseContainer
base( derived
);
35 BOOST_CHECK_EQUAL( derived
.size(), base
.size() );
38 BOOST_CHECK_EQUAL( derived
.size(), base
.size() );
42 template< class Cont
, class T
>
43 void test_unordered_interface()
48 typename
Cont::local_iterator i
= c
.begin( 0 );
49 typename
Cont::const_local_iterator ci
= i
;
53 typename
Cont::size_type s
= c
.bucket_count();
55 s
= c
.max_bucket_count();
56 s
= c
.bucket_size( 0 );
58 float f
= c
.load_factor();
59 f
= c
.max_load_factor();
66 template< class PtrSet
>
70 typedef typename
PtrSet::key_type T
;
77 BOOST_CHECK_EQUAL( s
.size(), 3u );
78 BOOST_CHECK_EQUAL( hash_value(t
), hash_value(*t2
) );
79 BOOST_CHECK_EQUAL( t
, *t2
);
81 typename
PtrSet::iterator i
= s
.find( t
);
83 BOOST_CHECK( i
!= s
.end() );
84 unsigned n
= s
.erase( t
);
89 #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
90 #pragma GCC diagnostic push
91 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
97 ptr_set_test
< ptr_unordered_set
<Base
>, Base
, Derived_class
, false >();
98 ptr_set_test
< ptr_unordered_set
<Value
>, Value
, Value
, false >();
100 ptr_set_test
< ptr_unordered_multiset
<Base
>, Base
, Derived_class
, false >();
101 ptr_set_test
< ptr_unordered_multiset
<Value
>, Value
, Value
, false >();
103 test_copy
< ptr_unordered_set
<Base
>, ptr_unordered_set
<Derived_class
>,
105 test_copy
< ptr_unordered_multiset
<Base
>, ptr_unordered_multiset
<Derived_class
>,
108 test_transfer
< ptr_unordered_set
<Derived_class
>, ptr_unordered_set
<Base
>, Derived_class
>();
109 test_transfer
< ptr_unordered_multiset
<Derived_class
>, ptr_unordered_multiset
<Base
>, Derived_class
>();
111 ptr_unordered_set
<int> set
;
113 BOOST_CHECK_THROW( set
.insert( 0 ), bad_ptr_container_operation
);
114 set
.insert( new int(0) );
115 #ifndef BOOST_NO_AUTO_PTR
116 std::auto_ptr
<int> ap( new int(1) );
119 #ifndef BOOST_NO_CXX11_SMART_PTR
120 std::unique_ptr
<int> up( new int(2) );
121 set
.insert( std::move( up
) );
123 BOOST_CHECK_THROW( (set
.replace(set
.begin(), 0 )), bad_ptr_container_operation
);
124 #ifndef BOOST_NO_AUTO_PTR
125 BOOST_CHECK_THROW( (set
.replace(set
.begin(), std::auto_ptr
<int>(0) )), bad_ptr_container_operation
);
127 #if !defined(BOOST_NO_CXX11_SMART_PTR) && !defined(BOOST_NO_CXX11_NULLPTR)
128 BOOST_CHECK_THROW( (set
.replace(set
.begin(), std::unique_ptr
<int>(nullptr) )), bad_ptr_container_operation
);
131 test_unordered_interface
< ptr_unordered_set
<Base
>, Derived_class
>();
132 test_unordered_interface
< ptr_unordered_multiset
<Base
>, Derived_class
>();
134 test_erase
< ptr_unordered_set
<Base
> >();
135 test_erase
< ptr_unordered_multiset
<Base
> >();
138 #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
139 #pragma GCC diagnostic pop
142 using boost::unit_test::test_suite
;
144 test_suite
* init_unit_test_suite( int argc
, char* argv
[] )
146 test_suite
* test
= BOOST_TEST_SUITE( "Pointer Container Test Suite" );
148 test
->add( BOOST_TEST_CASE( &test_set
) );