| 
									
										
										
										
											2006-05-17 17:19:16 +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-17 17:19:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // This header contains metafunctions/functions to get the equivalent
 | 
					
						
							|  |  |  | // associative container for an unordered container, and compare the contents.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if !defined(BOOST_UNORDERED_TEST_HELPERS_TRACKER_HEADER)
 | 
					
						
							|  |  |  | #define BOOST_UNORDERED_TEST_HELPERS_TRACKER_HEADER
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <set>
 | 
					
						
							|  |  |  | #include <map>
 | 
					
						
							|  |  |  | #include <iterator>
 | 
					
						
							|  |  |  | #include <algorithm>
 | 
					
						
							| 
									
										
										
										
											2006-06-12 23:30:46 +00:00
										 |  |  | #include <boost/type_traits/is_same.hpp>
 | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  | #include "../objects/fwd.hpp"
 | 
					
						
							|  |  |  | #include "./metafunctions.hpp"
 | 
					
						
							|  |  |  | #include "./helpers.hpp"
 | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  | #include "./equivalent.hpp"
 | 
					
						
							| 
									
										
											  
											
												Merge in support for equality operators for the unordered containers and
hopefully better cross-platform support.
Merged revisions 44778-44835,44837-44918 via svnmerge from 
https://svn.boost.org/svn/boost/branches/unordered/trunk
........
  r44778 | danieljames | 2008-04-26 17:15:44 +0100 (Sat, 26 Apr 2008) | 2 lines
  
  Remove a trailing comma.
........
  r44779 | danieljames | 2008-04-26 17:23:51 +0100 (Sat, 26 Apr 2008) | 1 line
  
  Merge in support for equality operators.
........
  r44780 | danieljames | 2008-04-26 17:28:44 +0100 (Sat, 26 Apr 2008) | 1 line
  
  Use my own list container to avoid working around STL container bugs.
........
  r44833 | danieljames | 2008-04-28 08:03:43 +0100 (Mon, 28 Apr 2008) | 1 line
  
  Better equality tests.
........
  r44834 | danieljames | 2008-04-28 08:04:03 +0100 (Mon, 28 Apr 2008) | 1 line
  
  Remove a superfluous check.
........
  r44835 | danieljames | 2008-04-28 08:04:21 +0100 (Mon, 28 Apr 2008) | 1 line
  
  Add equality reference documentation.
........
  r44916 | danieljames | 2008-04-30 08:16:52 +0100 (Wed, 30 Apr 2008) | 1 line
  
  New version of list.hpp
........
  r44917 | danieljames | 2008-04-30 08:18:31 +0100 (Wed, 30 Apr 2008) | 1 line
  
  Support compilers without ADL in the compile tests.
........
  r44918 | danieljames | 2008-04-30 08:25:20 +0100 (Wed, 30 Apr 2008) | 7 lines
  
  Change the typedef of buffered functions as it was confusing MSVC 6.5
  
  get_allocator wasn't compiling when the allocator workaround is used because it
  couldn't cast from the wrapped allocator to an allocator of another type. So
  use value_alloc_ when it's available (it's only unavailable on compilers with
  C++0x support, which don't require the workaround).
........
[SVN r44919]
											
										 
											2008-04-30 07:57:04 +00:00
										 |  |  | #include "./list.hpp"
 | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace test | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-07-08 11:55:10 +00:00
										 |  |  |     template <typename X> | 
					
						
							|  |  |  |     struct equals_to_compare | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2012-07-08 11:55:10 +00:00
										 |  |  |         typedef std::less<BOOST_DEDUCED_TYPENAME X::first_argument_type> | 
					
						
							|  |  |  |             type; | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-08 11:55:10 +00:00
										 |  |  |     template <> | 
					
						
							|  |  |  |     struct equals_to_compare<test::equal_to> | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2012-07-08 11:55:10 +00:00
										 |  |  |         typedef test::less type; | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     template <class X1, class X2> | 
					
						
							|  |  |  |     void compare_range(X1 const& x1, X2 const& x2) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
											  
											
												Merge in support for equality operators for the unordered containers and
hopefully better cross-platform support.
Merged revisions 44778-44835,44837-44918 via svnmerge from 
https://svn.boost.org/svn/boost/branches/unordered/trunk
........
  r44778 | danieljames | 2008-04-26 17:15:44 +0100 (Sat, 26 Apr 2008) | 2 lines
  
  Remove a trailing comma.
........
  r44779 | danieljames | 2008-04-26 17:23:51 +0100 (Sat, 26 Apr 2008) | 1 line
  
  Merge in support for equality operators.
........
  r44780 | danieljames | 2008-04-26 17:28:44 +0100 (Sat, 26 Apr 2008) | 1 line
  
  Use my own list container to avoid working around STL container bugs.
........
  r44833 | danieljames | 2008-04-28 08:03:43 +0100 (Mon, 28 Apr 2008) | 1 line
  
  Better equality tests.
........
  r44834 | danieljames | 2008-04-28 08:04:03 +0100 (Mon, 28 Apr 2008) | 1 line
  
  Remove a superfluous check.
........
  r44835 | danieljames | 2008-04-28 08:04:21 +0100 (Mon, 28 Apr 2008) | 1 line
  
  Add equality reference documentation.
........
  r44916 | danieljames | 2008-04-30 08:16:52 +0100 (Wed, 30 Apr 2008) | 1 line
  
  New version of list.hpp
........
  r44917 | danieljames | 2008-04-30 08:18:31 +0100 (Wed, 30 Apr 2008) | 1 line
  
  Support compilers without ADL in the compile tests.
........
  r44918 | danieljames | 2008-04-30 08:25:20 +0100 (Wed, 30 Apr 2008) | 7 lines
  
  Change the typedef of buffered functions as it was confusing MSVC 6.5
  
  get_allocator wasn't compiling when the allocator workaround is used because it
  couldn't cast from the wrapped allocator to an allocator of another type. So
  use value_alloc_ when it's available (it's only unavailable on compilers with
  C++0x support, which don't require the workaround).
........
[SVN r44919]
											
										 
											2008-04-30 07:57:04 +00:00
										 |  |  |         typedef test::list<BOOST_DEDUCED_TYPENAME X1::value_type> value_list; | 
					
						
							|  |  |  |         value_list values1(x1.begin(), x1.end()); | 
					
						
							|  |  |  |         value_list values2(x2.begin(), x2.end()); | 
					
						
							|  |  |  |         values1.sort(); | 
					
						
							|  |  |  |         values2.sort(); | 
					
						
							| 
									
										
										
										
											2009-05-27 17:44:09 +00:00
										 |  |  |         BOOST_TEST(values1.size() == values2.size() && | 
					
						
							| 
									
										
										
										
											2009-11-10 08:15:55 +00:00
										 |  |  |                 test::equal(values1.begin(), values1.end(), values2.begin(), | 
					
						
							| 
									
										
											  
											
												Merge in support for equality operators for the unordered containers and
hopefully better cross-platform support.
Merged revisions 44778-44835,44837-44918 via svnmerge from 
https://svn.boost.org/svn/boost/branches/unordered/trunk
........
  r44778 | danieljames | 2008-04-26 17:15:44 +0100 (Sat, 26 Apr 2008) | 2 lines
  
  Remove a trailing comma.
........
  r44779 | danieljames | 2008-04-26 17:23:51 +0100 (Sat, 26 Apr 2008) | 1 line
  
  Merge in support for equality operators.
........
  r44780 | danieljames | 2008-04-26 17:28:44 +0100 (Sat, 26 Apr 2008) | 1 line
  
  Use my own list container to avoid working around STL container bugs.
........
  r44833 | danieljames | 2008-04-28 08:03:43 +0100 (Mon, 28 Apr 2008) | 1 line
  
  Better equality tests.
........
  r44834 | danieljames | 2008-04-28 08:04:03 +0100 (Mon, 28 Apr 2008) | 1 line
  
  Remove a superfluous check.
........
  r44835 | danieljames | 2008-04-28 08:04:21 +0100 (Mon, 28 Apr 2008) | 1 line
  
  Add equality reference documentation.
........
  r44916 | danieljames | 2008-04-30 08:16:52 +0100 (Wed, 30 Apr 2008) | 1 line
  
  New version of list.hpp
........
  r44917 | danieljames | 2008-04-30 08:18:31 +0100 (Wed, 30 Apr 2008) | 1 line
  
  Support compilers without ADL in the compile tests.
........
  r44918 | danieljames | 2008-04-30 08:25:20 +0100 (Wed, 30 Apr 2008) | 7 lines
  
  Change the typedef of buffered functions as it was confusing MSVC 6.5
  
  get_allocator wasn't compiling when the allocator workaround is used because it
  couldn't cast from the wrapped allocator to an allocator of another type. So
  use value_alloc_ when it's available (it's only unavailable on compilers with
  C++0x support, which don't require the workaround).
........
[SVN r44919]
											
										 
											2008-04-30 07:57:04 +00:00
										 |  |  |                     test::equivalent)); | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     template <class X1, class X2, class T> | 
					
						
							|  |  |  |     void compare_pairs(X1 const& x1, X2 const& x2, T*) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
											  
											
												Merge in support for equality operators for the unordered containers and
hopefully better cross-platform support.
Merged revisions 44778-44835,44837-44918 via svnmerge from 
https://svn.boost.org/svn/boost/branches/unordered/trunk
........
  r44778 | danieljames | 2008-04-26 17:15:44 +0100 (Sat, 26 Apr 2008) | 2 lines
  
  Remove a trailing comma.
........
  r44779 | danieljames | 2008-04-26 17:23:51 +0100 (Sat, 26 Apr 2008) | 1 line
  
  Merge in support for equality operators.
........
  r44780 | danieljames | 2008-04-26 17:28:44 +0100 (Sat, 26 Apr 2008) | 1 line
  
  Use my own list container to avoid working around STL container bugs.
........
  r44833 | danieljames | 2008-04-28 08:03:43 +0100 (Mon, 28 Apr 2008) | 1 line
  
  Better equality tests.
........
  r44834 | danieljames | 2008-04-28 08:04:03 +0100 (Mon, 28 Apr 2008) | 1 line
  
  Remove a superfluous check.
........
  r44835 | danieljames | 2008-04-28 08:04:21 +0100 (Mon, 28 Apr 2008) | 1 line
  
  Add equality reference documentation.
........
  r44916 | danieljames | 2008-04-30 08:16:52 +0100 (Wed, 30 Apr 2008) | 1 line
  
  New version of list.hpp
........
  r44917 | danieljames | 2008-04-30 08:18:31 +0100 (Wed, 30 Apr 2008) | 1 line
  
  Support compilers without ADL in the compile tests.
........
  r44918 | danieljames | 2008-04-30 08:25:20 +0100 (Wed, 30 Apr 2008) | 7 lines
  
  Change the typedef of buffered functions as it was confusing MSVC 6.5
  
  get_allocator wasn't compiling when the allocator workaround is used because it
  couldn't cast from the wrapped allocator to an allocator of another type. So
  use value_alloc_ when it's available (it's only unavailable on compilers with
  C++0x support, which don't require the workaround).
........
[SVN r44919]
											
										 
											2008-04-30 07:57:04 +00:00
										 |  |  |         test::list<T> values1(x1.first, x1.second); | 
					
						
							|  |  |  |         test::list<T> values2(x2.first, x2.second); | 
					
						
							|  |  |  |         values1.sort(); | 
					
						
							|  |  |  |         values2.sort(); | 
					
						
							| 
									
										
										
										
											2009-05-27 17:44:09 +00:00
										 |  |  |         BOOST_TEST(values1.size() == values2.size() && | 
					
						
							| 
									
										
										
										
											2010-01-04 22:49:39 +00:00
										 |  |  |                 test::equal(values1.begin(), values1.end(), | 
					
						
							|  |  |  |                     values2.begin(), test::equivalent)); | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-08 11:55:10 +00:00
										 |  |  |     template <typename X> | 
					
						
							|  |  |  |     struct ordered_base; | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-08 11:55:10 +00:00
										 |  |  |     template <class V, class H, class P, class A> | 
					
						
							|  |  |  |     struct ordered_base<boost::unordered_set<V, H, P, A> > | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         typedef std::set<V, | 
					
						
							|  |  |  |             BOOST_DEDUCED_TYPENAME equals_to_compare<P>::type> | 
					
						
							|  |  |  |             type; | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-08 11:55:10 +00:00
										 |  |  |     template <class V, class H, class P, class A> | 
					
						
							|  |  |  |     struct ordered_base<boost::unordered_multiset<V, H, P, A> > | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         typedef std::multiset<V, | 
					
						
							|  |  |  |             BOOST_DEDUCED_TYPENAME equals_to_compare<P>::type> | 
					
						
							|  |  |  |             type; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     template <class K, class M, class H, class P, class A> | 
					
						
							|  |  |  |     struct ordered_base<boost::unordered_map<K, M, H, P, A> > | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         typedef std::map<K, M, | 
					
						
							|  |  |  |             BOOST_DEDUCED_TYPENAME equals_to_compare<P>::type> | 
					
						
							|  |  |  |             type; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     template <class K, class M, class H, class P, class A> | 
					
						
							|  |  |  |     struct ordered_base<boost::unordered_multimap<K, M, H, P, A> > | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         typedef std::multimap<K, M, | 
					
						
							|  |  |  |             BOOST_DEDUCED_TYPENAME equals_to_compare<P>::type> | 
					
						
							|  |  |  |             type; | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     template <class X> | 
					
						
							|  |  |  |     class ordered : public ordered_base<X>::type | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2008-01-10 22:30:46 +00:00
										 |  |  |         typedef BOOST_DEDUCED_TYPENAME ordered_base<X>::type base; | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |     public: | 
					
						
							| 
									
										
										
										
											2008-01-10 22:30:46 +00:00
										 |  |  |         typedef BOOST_DEDUCED_TYPENAME base::key_compare key_compare; | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         ordered() | 
					
						
							|  |  |  |             : base() | 
					
						
							|  |  |  |         {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-07 10:57:35 +00:00
										 |  |  |         explicit ordered(key_compare const& kc) | 
					
						
							|  |  |  |             : base(kc) | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |         {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         void compare(X const& x) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             compare_range(x, *this); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-04 22:49:39 +00:00
										 |  |  |         void compare_key(X const& x, | 
					
						
							|  |  |  |             BOOST_DEDUCED_TYPENAME X::value_type const& val) | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |         { | 
					
						
							|  |  |  |             compare_pairs( | 
					
						
							|  |  |  |                 x.equal_range(get_key<X>(val)), | 
					
						
							|  |  |  |                 this->equal_range(get_key<X>(val)), | 
					
						
							| 
									
										
											  
											
												Merge in support for equality operators for the unordered containers and
hopefully better cross-platform support.
Merged revisions 44778-44835,44837-44918 via svnmerge from 
https://svn.boost.org/svn/boost/branches/unordered/trunk
........
  r44778 | danieljames | 2008-04-26 17:15:44 +0100 (Sat, 26 Apr 2008) | 2 lines
  
  Remove a trailing comma.
........
  r44779 | danieljames | 2008-04-26 17:23:51 +0100 (Sat, 26 Apr 2008) | 1 line
  
  Merge in support for equality operators.
........
  r44780 | danieljames | 2008-04-26 17:28:44 +0100 (Sat, 26 Apr 2008) | 1 line
  
  Use my own list container to avoid working around STL container bugs.
........
  r44833 | danieljames | 2008-04-28 08:03:43 +0100 (Mon, 28 Apr 2008) | 1 line
  
  Better equality tests.
........
  r44834 | danieljames | 2008-04-28 08:04:03 +0100 (Mon, 28 Apr 2008) | 1 line
  
  Remove a superfluous check.
........
  r44835 | danieljames | 2008-04-28 08:04:21 +0100 (Mon, 28 Apr 2008) | 1 line
  
  Add equality reference documentation.
........
  r44916 | danieljames | 2008-04-30 08:16:52 +0100 (Wed, 30 Apr 2008) | 1 line
  
  New version of list.hpp
........
  r44917 | danieljames | 2008-04-30 08:18:31 +0100 (Wed, 30 Apr 2008) | 1 line
  
  Support compilers without ADL in the compile tests.
........
  r44918 | danieljames | 2008-04-30 08:25:20 +0100 (Wed, 30 Apr 2008) | 7 lines
  
  Change the typedef of buffered functions as it was confusing MSVC 6.5
  
  get_allocator wasn't compiling when the allocator workaround is used because it
  couldn't cast from the wrapped allocator to an allocator of another type. So
  use value_alloc_ when it's available (it's only unavailable on compilers with
  C++0x support, which don't require the workaround).
........
[SVN r44919]
											
										 
											2008-04-30 07:57:04 +00:00
										 |  |  |                 (BOOST_DEDUCED_TYPENAME X::value_type*) 0); | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2006-06-12 23:30:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         template <class It> | 
					
						
							| 
									
										
										
										
											2012-05-07 10:57:35 +00:00
										 |  |  |         void insert_range(It b, It e) { | 
					
						
							|  |  |  |             while(b != e) { | 
					
						
							|  |  |  |                 this->insert(*b); | 
					
						
							|  |  |  |                 ++b; | 
					
						
							| 
									
										
										
										
											2006-06-12 23:30:46 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     template <class Equals> | 
					
						
							| 
									
										
										
										
											2010-01-04 22:49:39 +00:00
										 |  |  |     BOOST_DEDUCED_TYPENAME | 
					
						
							|  |  |  |         equals_to_compare<Equals>::type create_compare(Equals const&) | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2008-01-10 22:30:46 +00:00
										 |  |  |         BOOST_DEDUCED_TYPENAME equals_to_compare<Equals>::type x; | 
					
						
							| 
									
										
										
										
											2006-06-12 23:30:46 +00:00
										 |  |  |         return x; | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     template <class X> | 
					
						
							|  |  |  |     ordered<X> create_ordered(X const& container) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return ordered<X>(create_compare(container.key_eq())); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     template <class X1, class X2> | 
					
						
							|  |  |  |     void check_container(X1 const& container, X2 const& values) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         ordered<X1> tracker = create_ordered(container); | 
					
						
							| 
									
										
										
										
											2006-06-12 23:30:46 +00:00
										 |  |  |         tracker.insert_range(values.begin(), values.end()); | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |         tracker.compare(container); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 |