2 // Copyright 2005-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 #if !defined(BOOST_UNORDERED_TESTS_EQUIVALENT_HEADER)
7 #define BOOST_UNORDERED_TESTS_EQUIVALENT_HEADER
11 #include "./metafunctions.hpp"
13 #include <boost/core/lightweight_test.hpp>
14 #include <boost/unordered_map.hpp>
15 #include <boost/unordered_set.hpp>
18 template <class T1, class T2>
19 bool equivalent_impl(T1 const& x, T2 const& y, base_type)
26 boost::hash<T> const&, boost::hash<T> const&, derived_type)
33 std::equal_to<T> const&, std::equal_to<T> const&, derived_type)
38 template <class T1, class T2, class T3, class T4>
40 std::pair<T1, T2> const& x1, std::pair<T3, T4> const& x2, derived_type)
42 return equivalent_impl(x1.first, x2.first, derived) &&
43 equivalent_impl(x1.second, x2.second, derived);
46 struct equivalent_type
50 template <class T1, class T2>
51 bool operator()(T1 const& x, T2 const& y) const
53 return equivalent_impl(x, y, derived);
57 const equivalent_type equivalent;
59 template <class Container> class unordered_equivalence_tester
61 typename Container::size_type size_;
62 typename Container::hasher hasher_;
63 typename Container::key_equal key_equal_;
64 float max_load_factor_;
66 typedef test::list<typename Container::value_type> value_list;
70 unordered_equivalence_tester(Container const& x)
71 : size_(x.size()), hasher_(x.hash_function()), key_equal_(x.key_eq()),
72 max_load_factor_(x.max_load_factor()), values_(x.begin(), x.end())
77 bool operator()(Container const& x) const
79 if (!((size_ == x.size()) &&
80 (test::equivalent(hasher_, x.hash_function())) &&
81 (test::equivalent(key_equal_, x.key_eq())) &&
82 (max_load_factor_ == x.max_load_factor()) &&
83 (values_.size() == x.size())))
86 value_list copy(x.begin(), x.end());
88 return values_ == copy;
92 unordered_equivalence_tester();