]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | |
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) | |
5 | ||
6 | #if !defined(BOOST_UNORDERED_TESTS_EQUIVALENT_HEADER) | |
7 | #define BOOST_UNORDERED_TESTS_EQUIVALENT_HEADER | |
8 | ||
7c673cae FG |
9 | #include "./fwd.hpp" |
10 | #include "./list.hpp" | |
b32b8144 FG |
11 | #include "./metafunctions.hpp" |
12 | #include <algorithm> | |
13 | #include <boost/detail/lightweight_test.hpp> | |
14 | #include <boost/unordered_map.hpp> | |
15 | #include <boost/unordered_set.hpp> | |
7c673cae | 16 | |
b32b8144 FG |
17 | namespace test { |
18 | template <class T1, class T2> | |
19 | bool equivalent_impl(T1 const& x, T2 const& y, base_type) | |
20 | { | |
21 | return x == y; | |
22 | } | |
7c673cae | 23 | |
b32b8144 FG |
24 | template <class T> |
25 | bool equivalent_impl( | |
26 | boost::hash<T> const&, boost::hash<T> const&, derived_type) | |
27 | { | |
28 | return true; | |
29 | } | |
30 | ||
31 | template <class T> | |
32 | bool equivalent_impl( | |
33 | std::equal_to<T> const&, std::equal_to<T> const&, derived_type) | |
34 | { | |
35 | return true; | |
36 | } | |
37 | ||
38 | template <class T1, class T2, class T3, class T4> | |
39 | bool equivalent_impl( | |
40 | std::pair<T1, T2> const& x1, std::pair<T3, T4> const& x2, derived_type) | |
41 | { | |
42 | return equivalent_impl(x1.first, x2.first, derived) && | |
43 | equivalent_impl(x1.second, x2.second, derived); | |
44 | } | |
7c673cae | 45 | |
b32b8144 FG |
46 | struct equivalent_type |
47 | { | |
48 | equivalent_type() {} | |
49 | ||
50 | template <class T1, class T2> | |
51 | bool operator()(T1 const& x, T2 const& y) const | |
7c673cae | 52 | { |
b32b8144 | 53 | return equivalent_impl(x, y, derived); |
7c673cae | 54 | } |
b32b8144 | 55 | }; |
7c673cae | 56 | |
b32b8144 | 57 | const equivalent_type equivalent; |
7c673cae | 58 | |
b32b8144 FG |
59 | template <class Container> class unordered_equivalence_tester |
60 | { | |
61 | BOOST_DEDUCED_TYPENAME Container::size_type size_; | |
62 | BOOST_DEDUCED_TYPENAME Container::hasher hasher_; | |
63 | BOOST_DEDUCED_TYPENAME Container::key_equal key_equal_; | |
64 | float max_load_factor_; | |
7c673cae | 65 | |
b32b8144 FG |
66 | typedef test::list<BOOST_DEDUCED_TYPENAME Container::value_type> value_list; |
67 | value_list values_; | |
7c673cae | 68 | |
b32b8144 FG |
69 | public: |
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()) | |
73 | { | |
74 | values_.sort(); | |
75 | } | |
7c673cae | 76 | |
b32b8144 | 77 | bool operator()(Container const& x) const |
7c673cae | 78 | { |
b32b8144 FG |
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()))) | |
84 | return false; | |
85 | ||
86 | value_list copy(x.begin(), x.end()); | |
87 | copy.sort(); | |
88 | return values_ == copy; | |
89 | } | |
90 | ||
91 | private: | |
92 | unordered_equivalence_tester(); | |
93 | }; | |
7c673cae FG |
94 | } |
95 | ||
96 | #endif |