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 // This header contains metafunctions/functions to get the equivalent
7 // associative container for an unordered container, and compare the contents.
9 #if !defined(BOOST_UNORDERED_TEST_HELPERS_TRACKER_HEADER)
10 #define BOOST_UNORDERED_TEST_HELPERS_TRACKER_HEADER
16 #include "../objects/fwd.hpp"
17 #include "./metafunctions.hpp"
18 #include "./helpers.hpp"
19 #include "./equivalent.hpp"
25 struct equals_to_compare
27 typedef std::less<BOOST_DEDUCED_TYPENAME X::first_argument_type>
32 struct equals_to_compare<test::equal_to>
34 typedef test::less type;
37 template <class X1, class X2>
38 void compare_range(X1 const& x1, X2 const& x2)
40 typedef test::list<BOOST_DEDUCED_TYPENAME X1::value_type> value_list;
41 value_list values1(x1.begin(), x1.end());
42 value_list values2(x2.begin(), x2.end());
45 BOOST_TEST(values1.size() == values2.size() &&
46 test::equal(values1.begin(), values1.end(), values2.begin(),
50 template <class X1, class X2, class T>
51 void compare_pairs(X1 const& x1, X2 const& x2, T*)
53 test::list<T> values1(x1.first, x1.second);
54 test::list<T> values2(x2.first, x2.second);
57 BOOST_TEST(values1.size() == values2.size() &&
58 test::equal(values1.begin(), values1.end(),
59 values2.begin(), test::equivalent));
63 bool is_set = test::is_set<X>::value,
64 bool has_unique_keys = test::has_unique_keys<X>::value>
68 struct ordered_base<X, true, true>
71 BOOST_DEDUCED_TYPENAME X::value_type,
72 BOOST_DEDUCED_TYPENAME equals_to_compare<BOOST_DEDUCED_TYPENAME X::key_equal>::type>
77 struct ordered_base<X, true, false>
79 typedef std::multiset<
80 BOOST_DEDUCED_TYPENAME X::value_type,
81 BOOST_DEDUCED_TYPENAME equals_to_compare<BOOST_DEDUCED_TYPENAME X::key_equal>::type>
86 struct ordered_base<X, false, true>
89 BOOST_DEDUCED_TYPENAME X::key_type,
90 BOOST_DEDUCED_TYPENAME X::mapped_type,
91 BOOST_DEDUCED_TYPENAME equals_to_compare<BOOST_DEDUCED_TYPENAME X::key_equal>::type>
96 struct ordered_base<X, false, false>
98 typedef std::multimap<
99 BOOST_DEDUCED_TYPENAME X::key_type,
100 BOOST_DEDUCED_TYPENAME X::mapped_type,
101 BOOST_DEDUCED_TYPENAME equals_to_compare<BOOST_DEDUCED_TYPENAME X::key_equal>::type>
106 class ordered : public ordered_base<X>::type
108 typedef BOOST_DEDUCED_TYPENAME ordered_base<X>::type base;
110 typedef BOOST_DEDUCED_TYPENAME base::key_compare key_compare;
116 explicit ordered(key_compare const& kc)
120 void compare(X const& x)
122 compare_range(x, *this);
125 void compare_key(X const& x,
126 BOOST_DEDUCED_TYPENAME X::value_type const& val)
129 x.equal_range(get_key<X>(val)),
130 this->equal_range(get_key<X>(val)),
131 (BOOST_DEDUCED_TYPENAME X::value_type*) 0);
135 void insert_range(It b, It e) {
143 template <class Equals>
144 BOOST_DEDUCED_TYPENAME
145 equals_to_compare<Equals>::type create_compare(Equals const&)
147 BOOST_DEDUCED_TYPENAME equals_to_compare<Equals>::type x;
152 ordered<X> create_ordered(X const& container)
154 return ordered<X>(create_compare(container.key_eq()));
157 template <class X1, class X2>
158 void check_container(X1 const& container, X2 const& values)
160 ordered<X1> tracker = create_ordered(container);
161 tracker.insert_range(values.begin(), values.end());
162 tracker.compare(container);