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
9 #include <boost/unordered_map.hpp>
10 #include <boost/unordered_set.hpp>
12 #include "./metafunctions.hpp"
18 template <class T1, class T2>
19 bool equivalent_impl(T1 const& x, T2 const& y, base_type) {
24 bool equivalent_impl(boost::hash<T> const&, boost::hash<T> const&,
31 bool equivalent_impl(std::equal_to<T> const&, std::equal_to<T> const&,
37 template <class T1, class T2, class T3, class T4>
38 bool equivalent_impl(std::pair<T1, T2> const& x1,
39 std::pair<T3, T4> const& x2, derived_type) {
40 return equivalent_impl(x1.first, x2.first, derived) &&
41 equivalent_impl(x1.second, x2.second, derived);
44 struct equivalent_type {
47 template <class T1, class T2>
48 bool operator()(T1 const& x, T2 const& y) const {
49 return equivalent_impl(x, y, derived);
53 const equivalent_type equivalent;
55 template <class Container>
56 class unordered_equivalence_tester
58 BOOST_DEDUCED_TYPENAME Container::size_type size_;
59 BOOST_DEDUCED_TYPENAME Container::hasher hasher_;
60 BOOST_DEDUCED_TYPENAME Container::key_equal key_equal_;
61 float max_load_factor_;
63 typedef test::list<BOOST_DEDUCED_TYPENAME Container::value_type>
67 unordered_equivalence_tester(Container const &x)
69 hasher_(x.hash_function()), key_equal_(x.key_eq()),
70 max_load_factor_(x.max_load_factor()),
71 values_(x.begin(), x.end())
76 bool operator()(Container const& x) const
78 if(!((size_ == x.size()) &&
79 (test::equivalent(hasher_, x.hash_function())) &&
80 (test::equivalent(key_equal_, x.key_eq())) &&
81 (max_load_factor_ == x.max_load_factor()) &&
82 (values_.size() == x.size()))) return false;
84 value_list copy(x.begin(), x.end());
86 return values_ == copy;
89 unordered_equivalence_tester();