]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | |
2 | // Copyright 2007-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 | ||
b32b8144 | 6 | // clang-format off |
7c673cae FG |
7 | #include "../helpers/prefix.hpp" |
8 | #include <boost/unordered_set.hpp> | |
9 | #include <boost/unordered_map.hpp> | |
10 | #include "../helpers/postfix.hpp" | |
b32b8144 | 11 | // clang-format on |
7c673cae FG |
12 | |
13 | #include "../helpers/test.hpp" | |
14 | ||
b32b8144 FG |
15 | namespace insert_stable { |
16 | struct member | |
17 | { | |
18 | int tag1_; | |
19 | int tag2_; | |
7c673cae | 20 | |
b32b8144 FG |
21 | member() : tag1_(0), tag2_(0) {} |
22 | member(int t1, int t2) : tag1_(t1), tag2_(t2) {} | |
23 | ||
24 | friend bool operator==(member const& x, member const& y) | |
25 | { | |
26 | return x.tag1_ == y.tag1_; | |
27 | } | |
28 | ||
29 | friend bool operator!=(member const& x, member const& y) | |
30 | { | |
31 | return x.tag1_ != y.tag1_; | |
32 | } | |
33 | }; | |
7c673cae FG |
34 | } |
35 | ||
36 | #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP | |
37 | namespace boost | |
38 | #else | |
39 | namespace insert_stable | |
40 | #endif | |
41 | { | |
b32b8144 FG |
42 | std::size_t hash_value(insert_stable::member const& x) |
43 | { | |
44 | return static_cast<std::size_t>(x.tag1_); | |
45 | } | |
7c673cae FG |
46 | } |
47 | ||
b32b8144 FG |
48 | // This is no longer supported, as there's no longer an efficient way to get to |
49 | // the end of a group of equivalent nodes. | |
50 | #if 0 | |
51 | ||
52 | UNORDERED_AUTO_TEST(stable_insert_test1) | |
53 | { | |
7c673cae FG |
54 | boost::unordered_multiset<insert_stable::member> x; |
55 | ||
b32b8144 FG |
56 | x.insert(insert_stable::member(1, 1)); |
57 | x.insert(insert_stable::member(1, 2)); | |
58 | x.insert(insert_stable::member(1, 3)); | |
7c673cae | 59 | |
b32b8144 | 60 | BOOST_TEST(x.count(insert_stable::member(1, 4)) == 3); |
7c673cae FG |
61 | |
62 | boost::unordered_multiset<insert_stable::member>::const_iterator | |
b32b8144 FG |
63 | it = x.begin(), |
64 | end = x.end(); | |
7c673cae | 65 | BOOST_TEST(it != end); |
b32b8144 FG |
66 | if (it != end) { |
67 | BOOST_TEST(it->tag2_ == 1); | |
68 | ++it; | |
69 | } | |
7c673cae | 70 | BOOST_TEST(it != end); |
b32b8144 FG |
71 | if (it != end) { |
72 | BOOST_TEST(it->tag2_ == 2); | |
73 | ++it; | |
74 | } | |
7c673cae | 75 | BOOST_TEST(it != end); |
b32b8144 FG |
76 | if (it != end) { |
77 | BOOST_TEST(it->tag2_ == 3); | |
78 | ++it; | |
79 | } | |
7c673cae FG |
80 | BOOST_TEST(it == end); |
81 | } | |
82 | ||
b32b8144 FG |
83 | UNORDERED_AUTO_TEST(stable_insert_test2) |
84 | { | |
7c673cae | 85 | boost::unordered_multimap<insert_stable::member, int> x; |
b32b8144 FG |
86 | typedef boost::unordered_multimap<insert_stable::member, |
87 | int>::const_iterator iterator; | |
7c673cae | 88 | |
b32b8144 FG |
89 | iterator it = x.emplace(insert_stable::member(1, 1), 1); |
90 | it = x.emplace(insert_stable::member(1, 2), 2); | |
91 | it = x.emplace(insert_stable::member(1, 3), 3); | |
7c673cae | 92 | |
b32b8144 | 93 | BOOST_TEST(x.count(insert_stable::member(1, 4)) == 3); |
7c673cae FG |
94 | |
95 | it = x.begin(); | |
96 | iterator end = x.end(); | |
97 | BOOST_TEST(it != end); | |
b32b8144 FG |
98 | if (it != end) { |
99 | BOOST_TEST(it->first.tag2_ == 1 && it->second == 1); | |
100 | ++it; | |
101 | } | |
7c673cae | 102 | BOOST_TEST(it != end); |
b32b8144 FG |
103 | if (it != end) { |
104 | BOOST_TEST(it->first.tag2_ == 2 && it->second == 2); | |
105 | ++it; | |
106 | } | |
7c673cae | 107 | BOOST_TEST(it != end); |
b32b8144 FG |
108 | if (it != end) { |
109 | BOOST_TEST(it->first.tag2_ == 3 && it->second == 3); | |
110 | ++it; | |
111 | } | |
7c673cae FG |
112 | BOOST_TEST(it == end); |
113 | } | |
114 | ||
b32b8144 FG |
115 | #endif |
116 | ||
7c673cae | 117 | RUN_TESTS() |