2 // Copyright 2006-2009 Daniel James.
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #include "./containers.hpp"
8 #include "../helpers/invariants.hpp"
9 #include "../helpers/random_values.hpp"
10 #include "../helpers/tracker.hpp"
12 #if defined(BOOST_MSVC)
13 #pragma warning(disable : 4512) // assignment operator could not be generated
16 test::seed_t
initialize_seed(9387);
18 template <class T
> struct self_swap_base
: public test::exception_base
20 test::random_values
<T
> values
;
21 self_swap_base(std::size_t count
= 0) : values(count
, test::limited_range
) {}
24 T
init() const { return T(values
.begin(), values
.end()); }
31 test::check_container(x
, this->values
);
32 test::check_equivalent_keys(x
);
35 void check
BOOST_PREVENT_MACRO_SUBSTITUTION(T
const& x
) const
37 std::string
scope(test::scope
);
39 // TODO: In C++11 exceptions are only allowed in the swap function.
40 BOOST_TEST(scope
== "hash::hash(hash)" ||
41 scope
== "hash::operator=(hash)" ||
42 scope
== "equal_to::equal_to(equal_to)" ||
43 scope
== "equal_to::operator=(equal_to)");
45 test::check_equivalent_keys(x
);
49 template <class T
> struct self_swap_test1
: self_swap_base
<T
>
53 template <class T
> struct self_swap_test2
: self_swap_base
<T
>
55 self_swap_test2() : self_swap_base
<T
>(100) {}
58 template <class T
> struct swap_base
: public test::exception_base
60 const test::random_values
<T
> x_values
, y_values
;
61 const T initial_x
, initial_y
;
63 typedef BOOST_DEDUCED_TYPENAME
T::hasher hasher
;
64 typedef BOOST_DEDUCED_TYPENAME
T::key_equal key_equal
;
65 typedef BOOST_DEDUCED_TYPENAME
T::allocator_type allocator_type
;
67 swap_base(unsigned int count1
, unsigned int count2
, int tag1
, int tag2
)
68 : x_values(count1
, test::limited_range
),
69 y_values(count2
, test::limited_range
),
70 initial_x(x_values
.begin(), x_values
.end(), 0, hasher(tag1
),
71 key_equal(tag1
), allocator_type(tag1
)),
72 initial_y(y_values
.begin(), y_values
.end(), 0, hasher(tag2
),
74 allocator_type(T::allocator_type::propagate_on_container_swap::value
82 data_type(T
const& x_
, T
const& y_
) : x(x_
), y(y_
) {}
87 data_type
init() const { return data_type(initial_x
, initial_y
); }
89 void run(data_type
& d
) const
93 } catch (std::runtime_error
) {
97 test::check_container(d
.x
, this->y_values
);
98 test::check_equivalent_keys(d
.x
);
99 test::check_container(d
.y
, this->x_values
);
100 test::check_equivalent_keys(d
.y
);
103 void check
BOOST_PREVENT_MACRO_SUBSTITUTION(data_type
const& d
) const
105 std::string
scope(test::scope
);
107 // TODO: In C++11 exceptions are only allowed in the swap function.
108 BOOST_TEST(scope
== "hash::hash(hash)" ||
109 scope
== "hash::operator=(hash)" ||
110 scope
== "equal_to::equal_to(equal_to)" ||
111 scope
== "equal_to::operator=(equal_to)");
113 test::check_equivalent_keys(d
.x
);
114 test::check_equivalent_keys(d
.y
);
118 template <class T
> struct swap_test1
: swap_base
<T
>
120 swap_test1() : swap_base
<T
>(0, 0, 0, 0) {}
123 template <class T
> struct swap_test2
: swap_base
<T
>
125 swap_test2() : swap_base
<T
>(60, 0, 0, 0) {}
128 template <class T
> struct swap_test3
: swap_base
<T
>
130 swap_test3() : swap_base
<T
>(0, 60, 0, 0) {}
133 template <class T
> struct swap_test4
: swap_base
<T
>
135 swap_test4() : swap_base
<T
>(10, 10, 1, 2) {}
140 (self_swap_test1
)(self_swap_test2
)
141 (swap_test1
)(swap_test2
)(swap_test3
)(swap_test4
),