]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/unordered/test/helpers/equivalent.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / unordered / test / helpers / equivalent.hpp
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
9 #include <boost/unordered_map.hpp>
10 #include <boost/unordered_set.hpp>
11 #include <algorithm>
12 #include "./metafunctions.hpp"
13 #include "./fwd.hpp"
14 #include "./list.hpp"
15
16 namespace test
17 {
18 template <class T1, class T2>
19 bool equivalent_impl(T1 const& x, T2 const& y, base_type) {
20 return x == y;
21 }
22
23 template <class T>
24 bool equivalent_impl(boost::hash<T> const&, boost::hash<T> const&,
25 derived_type)
26 {
27 return true;
28 }
29
30 template <class T>
31 bool equivalent_impl(std::equal_to<T> const&, std::equal_to<T> const&,
32 derived_type)
33 {
34 return true;
35 }
36
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);
42 }
43
44 struct equivalent_type {
45 equivalent_type() {}
46
47 template <class T1, class T2>
48 bool operator()(T1 const& x, T2 const& y) const {
49 return equivalent_impl(x, y, derived);
50 }
51 };
52
53 const equivalent_type equivalent;
54
55 template <class Container>
56 class unordered_equivalence_tester
57 {
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_;
62
63 typedef test::list<BOOST_DEDUCED_TYPENAME Container::value_type>
64 value_list;
65 value_list values_;
66 public:
67 unordered_equivalence_tester(Container const &x)
68 : size_(x.size()),
69 hasher_(x.hash_function()), key_equal_(x.key_eq()),
70 max_load_factor_(x.max_load_factor()),
71 values_(x.begin(), x.end())
72 {
73 values_.sort();
74 }
75
76 bool operator()(Container const& x) const
77 {
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;
83
84 value_list copy(x.begin(), x.end());
85 copy.sort();
86 return values_ == copy;
87 }
88 private:
89 unordered_equivalence_tester();
90 };
91 }
92
93 #endif