| 
									
										
										
										
											2007-05-20 17:37:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-09 20:56:23 +00:00
										 |  |  | // Copyright 2007-2009 Daniel James.
 | 
					
						
							| 
									
										
										
										
											2007-05-20 17:37:27 +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)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  | // clang-format off
 | 
					
						
							| 
									
										
										
										
											2009-11-26 23:15:30 +00:00
										 |  |  | #include "../helpers/prefix.hpp"
 | 
					
						
							| 
									
										
										
										
											2007-05-20 17:37:27 +00:00
										 |  |  | #include <boost/unordered_set.hpp>
 | 
					
						
							|  |  |  | #include <boost/unordered_map.hpp>
 | 
					
						
							| 
									
										
										
										
											2012-04-08 15:29:15 +00:00
										 |  |  | #include "../helpers/postfix.hpp"
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  | // clang-format on
 | 
					
						
							| 
									
										
										
										
											2012-04-08 15:29:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-24 17:03:15 +00:00
										 |  |  | #include "../helpers/test.hpp"
 | 
					
						
							| 
									
										
										
										
											2007-05-20 17:37:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <iostream>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  | namespace insert_stable { | 
					
						
							|  |  |  | struct member | 
					
						
							| 
									
										
										
										
											2007-07-07 09:42:56 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |     int tag1_; | 
					
						
							|  |  |  |     int tag2_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     member() : tag1_(0), tag2_(0) {} | 
					
						
							|  |  |  |     member(int t1, int t2) : tag1_(t1), tag2_(t2) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     friend bool operator==(member const& x, member const& y) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return x.tag1_ == y.tag1_; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     friend bool operator!=(member const& x, member const& y) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return x.tag1_ != y.tag1_; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2007-07-07 09:42:56 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2007-05-20 17:37:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-07 09:42:56 +00:00
										 |  |  | #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
 | 
					
						
							|  |  |  | namespace boost | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | namespace insert_stable | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  | std::size_t hash_value(insert_stable::member const& x) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return static_cast<std::size_t>(x.tag1_); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2007-05-20 17:37:27 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-27 03:59:02 +00:00
										 |  |  | // This is now only supported when using grouped nodes. I can't see any
 | 
					
						
							|  |  |  | // efficient way to do it otherwise.
 | 
					
						
							|  |  |  | #if !BOOST_UNORDERED_INTEROPERABLE_NODES
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  | UNORDERED_AUTO_TEST(stable_insert_test1) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-07-07 09:42:56 +00:00
										 |  |  |     boost::unordered_multiset<insert_stable::member> x; | 
					
						
							| 
									
										
										
										
											2007-05-20 17:37:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |     x.insert(insert_stable::member(1, 1)); | 
					
						
							|  |  |  |     x.insert(insert_stable::member(1, 2)); | 
					
						
							|  |  |  |     x.insert(insert_stable::member(1, 3)); | 
					
						
							| 
									
										
										
										
											2007-05-20 17:37:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |     BOOST_TEST(x.count(insert_stable::member(1, 4)) == 3); | 
					
						
							| 
									
										
										
										
											2016-08-17 12:08:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-04 22:49:39 +00:00
										 |  |  |     boost::unordered_multiset<insert_stable::member>::const_iterator | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |         it = x.begin(), | 
					
						
							|  |  |  |         end = x.end(); | 
					
						
							| 
									
										
										
										
											2009-05-27 17:44:09 +00:00
										 |  |  |     BOOST_TEST(it != end); | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |     if (it != end) { | 
					
						
							|  |  |  |         BOOST_TEST(it->tag2_ == 1); | 
					
						
							|  |  |  |         ++it; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-05-27 17:44:09 +00:00
										 |  |  |     BOOST_TEST(it != end); | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |     if (it != end) { | 
					
						
							|  |  |  |         BOOST_TEST(it->tag2_ == 2); | 
					
						
							|  |  |  |         ++it; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-05-27 17:44:09 +00:00
										 |  |  |     BOOST_TEST(it != end); | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |     if (it != end) { | 
					
						
							|  |  |  |         BOOST_TEST(it->tag2_ == 3); | 
					
						
							|  |  |  |         ++it; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-05-27 17:44:09 +00:00
										 |  |  |     BOOST_TEST(it == end); | 
					
						
							| 
									
										
										
										
											2007-05-20 17:37:27 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  | UNORDERED_AUTO_TEST(stable_insert_test2) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-07-07 09:42:56 +00:00
										 |  |  |     boost::unordered_multimap<insert_stable::member, int> x; | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |     typedef boost::unordered_multimap<insert_stable::member, | 
					
						
							|  |  |  |         int>::const_iterator iterator; | 
					
						
							| 
									
										
										
										
											2007-05-20 17:37:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |     iterator it = x.emplace(insert_stable::member(1, 1), 1); | 
					
						
							|  |  |  |     it = x.emplace(insert_stable::member(1, 2), 2); | 
					
						
							|  |  |  |     it = x.emplace(insert_stable::member(1, 3), 3); | 
					
						
							| 
									
										
										
										
											2016-08-17 12:08:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |     BOOST_TEST(x.count(insert_stable::member(1, 4)) == 3); | 
					
						
							| 
									
										
										
										
											2007-05-20 17:37:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it = x.begin(); | 
					
						
							|  |  |  |     iterator end = x.end(); | 
					
						
							| 
									
										
										
										
											2009-05-27 17:44:09 +00:00
										 |  |  |     BOOST_TEST(it != end); | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |     if (it != end) { | 
					
						
							|  |  |  |         BOOST_TEST(it->first.tag2_ == 1 && it->second == 1); | 
					
						
							|  |  |  |         ++it; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-05-27 17:44:09 +00:00
										 |  |  |     BOOST_TEST(it != end); | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |     if (it != end) { | 
					
						
							|  |  |  |         BOOST_TEST(it->first.tag2_ == 2 && it->second == 2); | 
					
						
							|  |  |  |         ++it; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-05-27 17:44:09 +00:00
										 |  |  |     BOOST_TEST(it != end); | 
					
						
							| 
									
										
										
										
											2017-02-19 13:05:17 +00:00
										 |  |  |     if (it != end) { | 
					
						
							|  |  |  |         BOOST_TEST(it->first.tag2_ == 3 && it->second == 3); | 
					
						
							|  |  |  |         ++it; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-05-27 17:44:09 +00:00
										 |  |  |     BOOST_TEST(it == end); | 
					
						
							| 
									
										
										
										
											2007-05-20 17:37:27 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-27 03:59:02 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-24 17:03:15 +00:00
										 |  |  | RUN_TESTS() |