| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-09 20:56:23 +00:00
										 |  |  | // Copyright 2006-2009 Daniel James.
 | 
					
						
							| 
									
										
										
										
											2006-07-01 22:31:26 +00:00
										 |  |  | // Distributed under the Boost Software License, Version 1.0. (See accompanying
 | 
					
						
							|  |  |  | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "./containers.hpp"
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  | #include "../helpers/invariants.hpp"
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  | #include "../helpers/random_values.hpp"
 | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 08:15:55 +00:00
										 |  |  | #if defined(BOOST_MSVC)
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  | #pragma warning(disable : 4512) // assignment operator could not be generated
 | 
					
						
							| 
									
										
										
										
											2009-11-10 08:15:55 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-07 10:57:35 +00:00
										 |  |  | test::seed_t initialize_seed(9387); | 
					
						
							| 
									
										
										
										
											2007-12-06 11:42:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  | template <class T> struct self_swap_base : public test::exception_base | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     test::random_values<T> values; | 
					
						
							| 
									
										
										
										
											2016-10-05 09:45:53 +01:00
										 |  |  |     self_swap_base(std::size_t count = 0) : values(count) {} | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     typedef T data_type; | 
					
						
							|  |  |  |     T init() const { return T(values.begin(), values.end()); } | 
					
						
							|  |  |  |     void run(T& x) const { x.swap(x); } | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |     void check BOOST_PREVENT_MACRO_SUBSTITUTION(T const& x) const | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  |         std::string scope(test::scope); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-11 21:18:43 +00:00
										 |  |  |         // TODO: In C++11 exceptions are only allowed in the swap function.
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |         BOOST_TEST(scope == "hash::hash(hash)" || | 
					
						
							|  |  |  |                    scope == "hash::operator=(hash)" || | 
					
						
							|  |  |  |                    scope == "equal_to::equal_to(equal_to)" || | 
					
						
							|  |  |  |                    scope == "equal_to::operator=(equal_to)"); | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         test::check_equivalent_keys(x); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  | template <class T> struct self_swap_test1 : self_swap_base<T> | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  | template <class T> struct self_swap_test2 : self_swap_base<T> | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     self_swap_test2() : self_swap_base<T>(100) {} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  | template <class T> struct swap_base : public test::exception_base | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     const test::random_values<T> x_values, y_values; | 
					
						
							|  |  |  |     const T initial_x, initial_y; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-05 20:57:02 +00:00
										 |  |  |     typedef BOOST_DEDUCED_TYPENAME T::hasher hasher; | 
					
						
							|  |  |  |     typedef BOOST_DEDUCED_TYPENAME T::key_equal key_equal; | 
					
						
							|  |  |  |     typedef BOOST_DEDUCED_TYPENAME T::allocator_type allocator_type; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  |     swap_base(unsigned int count1, unsigned int count2, int tag1, int tag2) | 
					
						
							|  |  |  |         : x_values(count1), y_values(count2), | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |           initial_x(x_values.begin(), x_values.end(), 0, hasher(tag1), | 
					
						
							|  |  |  |               key_equal(tag1), allocator_type(tag1)), | 
					
						
							|  |  |  |           initial_y( | 
					
						
							|  |  |  |               y_values.begin(), y_values.end(), 0, hasher(tag2), | 
					
						
							|  |  |  |               key_equal(tag2), | 
					
						
							|  |  |  |               allocator_type( | 
					
						
							|  |  |  |                   T::allocator_type::propagate_on_container_swap::value ? tag2 | 
					
						
							|  |  |  |                                                                         : tag1)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     struct data_type | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         data_type(T const& x_, T const& y_) : x(x_), y(y_) {} | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         T x, y; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     data_type init() const { return data_type(initial_x, initial_y); } | 
					
						
							| 
									
										
										
										
											2012-08-25 21:54:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |     void run(data_type& d) const | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  |         try { | 
					
						
							|  |  |  |             d.x.swap(d.y); | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |         } catch (std::runtime_error) { | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |     void check BOOST_PREVENT_MACRO_SUBSTITUTION(data_type const& d) const | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2007-01-10 00:06:55 +00:00
										 |  |  |         std::string scope(test::scope); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-11 21:18:43 +00:00
										 |  |  |         // TODO: In C++11 exceptions are only allowed in the swap function.
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |         BOOST_TEST(scope == "hash::hash(hash)" || | 
					
						
							|  |  |  |                    scope == "hash::operator=(hash)" || | 
					
						
							|  |  |  |                    scope == "equal_to::equal_to(equal_to)" || | 
					
						
							|  |  |  |                    scope == "equal_to::operator=(equal_to)"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  |         test::check_equivalent_keys(d.x); | 
					
						
							|  |  |  |         test::check_equivalent_keys(d.y); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  | template <class T> struct swap_test1 : swap_base<T> | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     swap_test1() : swap_base<T>(0, 0, 0, 0) {} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  | template <class T> struct swap_test2 : swap_base<T> | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |     swap_test2() : swap_base<T>(60, 0, 0, 0) {} | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  | template <class T> struct swap_test3 : swap_base<T> | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |     swap_test3() : swap_base<T>(0, 60, 0, 0) {} | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  | template <class T> struct swap_test4 : swap_base<T> | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     swap_test4() : swap_base<T>(10, 10, 1, 2) {} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  | EXCEPTION_TESTS((self_swap_test1)(self_swap_test2)(swap_test1)(swap_test2)( | 
					
						
							|  |  |  |                     swap_test3)(swap_test4), | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  |     CONTAINER_SEQ) | 
					
						
							| 
									
										
										
										
											2012-12-07 17:05:36 +00:00
										 |  |  | RUN_TESTS() |