[AMDGPU][True16][CodeGen] true16 codegen pattern for f16 canonicalize (#122000)
[llvm-project.git] / libcxx / test / std / containers / unord / unord.multiset / eq.different_hash.pass.cpp
blob5b8f11e929279a57662c57c0675cf0e4623d2e2a
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 // <unordered_set>
11 // template <class Key, class T, class Hash, class Pred, class Alloc>
12 // bool
13 // operator==(const unordered_multiset<Key, T, Hash, Pred, Alloc>& x,
14 // const unordered_multiset<Key, T, Hash, Pred, Alloc>& y);
16 // template <class Key, class T, class Hash, class Pred, class Alloc>
17 // bool
18 // operator!=(const unordered_multiset<Key, T, Hash, Pred, Alloc>& x,
19 // const unordered_multiset<Key, T, Hash, Pred, Alloc>& y);
21 // Implements paper: http://wg21.link/p0809
23 #include <cassert>
24 #include <cstddef>
25 #include <functional>
26 #include <limits>
27 #include <unordered_set>
29 template <class T>
30 std::size_t hash_identity(T val) {
31 return val;
33 template <class T>
34 std::size_t hash_neg(T val) {
35 return std::numeric_limits<T>::max() - val;
37 template <class T>
38 std::size_t hash_scale(T val) {
39 return static_cast<std::size_t>(val << 1);
41 template <class T>
42 std::size_t hash_even(T val) {
43 return val & 1 ? 1 : 0;
45 template <class T>
46 std::size_t hash_same(T /*val*/) {
47 return 1;
50 template <class T>
51 std::size_t hash_identity(T* val) {
52 return *val;
54 template <class T>
55 std::size_t hash_neg(T* val) {
56 return std::numeric_limits<T>::max() - *val;
58 template <class T>
59 std::size_t hash_scale(T* val) {
60 return static_cast<std::size_t>(*val << 1);
62 template <class T>
63 std::size_t hash_even(T* val) {
64 return *val & 1 ? 1 : 0;
67 template <class T, std::size_t N>
68 void test(T (&vals)[N]) {
69 using Hash = std::size_t (*)(T);
70 using C = std::unordered_multiset<T, Hash, std::equal_to<T> >;
72 C c1(std::begin(vals), std::end(vals), 0, hash_identity);
73 C c2(std::begin(vals), std::end(vals), 0, hash_neg);
74 C c3(std::begin(vals), std::end(vals), 0, hash_scale);
75 C c4(std::begin(vals), std::end(vals), 0, hash_even);
76 C c5(std::begin(vals), std::end(vals), 0, hash_same);
78 assert(c1 == c1);
79 assert(c1 == c2);
80 assert(c1 == c3);
81 assert(c1 == c4);
82 assert(c1 == c5);
84 assert(c2 == c1);
85 assert(c2 == c2);
86 assert(c2 == c3);
87 assert(c2 == c4);
88 assert(c2 == c5);
90 assert(c3 == c1);
91 assert(c3 == c2);
92 assert(c3 == c3);
93 assert(c3 == c4);
94 assert(c3 == c5);
96 assert(c4 == c1);
97 assert(c4 == c2);
98 assert(c4 == c3);
99 assert(c4 == c4);
100 assert(c4 == c5);
102 assert(c5 == c1);
103 assert(c5 == c2);
104 assert(c5 == c3);
105 assert(c5 == c4);
106 assert(c5 == c5);
109 int main(int, char**) {
111 std::size_t vals[] = {
112 // clang-format off
114 2, 2,
115 3, 3, 3,
116 4, 4, 4, 4,
117 5, 5, 5, 5, 5,
118 6, 6, 6, 6, 6, 6,
119 7, 7, 7, 7, 7, 7, 7,
120 8, 8, 8, 8, 8, 8, 8, 8,
121 9, 9, 9, 9, 9, 9, 9, 9, 9,
123 // clang-format on
125 test(vals);
128 bool vals[] = {true, false};
129 test(vals);
132 char* vals[] = {(char*)("a"), (char*)("b"), (char*)("cde")};
133 test(vals);
136 return 0;