1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 // template <class Key, class T, class Hash, class Pred, class Alloc>
13 // operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
14 // const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
16 // template <class Key, class T, class Hash, class Pred, class Alloc>
18 // operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
19 // const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
21 // Implements paper: http://wg21.link/p0809
23 #include <unordered_map>
31 std::size_t hash_identity(T val
) {
35 std::size_t hash_neg(T val
) {
36 return std::numeric_limits
<T
>::max() - val
;
39 std::size_t hash_scale(T val
) {
40 return static_cast<std::size_t>(val
<< 1);
43 std::size_t hash_even(T val
) {
44 return val
& 1 ? 1 : 0;
47 std::size_t hash_same(T
/*val*/) {
52 std::size_t hash_identity(T
* val
) {
56 std::size_t hash_neg(T
* val
) {
57 return std::numeric_limits
<T
>::max() - *val
;
60 std::size_t hash_scale(T
* val
) {
61 return static_cast<std::size_t>(*val
<< 1);
64 std::size_t hash_even(T
* val
) {
65 return *val
& 1 ? 1 : 0;
68 template <class Map
, class Ittr
>
69 void populate(Map
& m
, Ittr start
, Ittr end
) {
70 for (auto *p1
= start
, *p2
= end
- 1; p1
!= end
; ++p1
, --p2
) {
71 m
.insert(std::make_pair(*p1
, *p2
));
75 template <class T
, std::size_t N
>
76 void test(T (&vals
)[N
]) {
77 using Hash
= std::size_t (*)(T
);
78 using C
= std::unordered_multimap
<T
, T
, Hash
, std::equal_to
<T
> >;
80 C
c1(0, hash_identity
);
86 populate(c1
, std::begin(vals
), std::end(vals
));
87 populate(c2
, std::begin(vals
), std::end(vals
));
88 populate(c3
, std::begin(vals
), std::end(vals
));
89 populate(c4
, std::begin(vals
), std::end(vals
));
90 populate(c5
, std::begin(vals
), std::end(vals
));
123 int main(int, char**) {
125 std::size_t vals
[] = {
134 8, 8, 8, 8, 8, 8, 8, 8,
135 9, 9, 9, 9, 9, 9, 9, 9, 9,
142 bool vals
[] = {true, false};
146 char* vals
[] = {(char*)("a"), (char*)("b"), (char*)("cde")};