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 //===----------------------------------------------------------------------===//
9 #ifndef TEST_TRANSPARENT_UNORDERED_H
10 #define TEST_TRANSPARENT_UNORDERED_H
12 #include "test_macros.h"
13 #include "is_transparent.h"
17 // testing transparent unordered containers
20 template <template <typename
...> class UnorderedSet
, typename Hash
,
22 using unord_set_type
= UnorderedSet
<StoredType
<int>, Hash
, Equal
>;
24 template <template <typename
...> class UnorderedMap
, typename Hash
,
26 using unord_map_type
= UnorderedMap
<StoredType
<int>, int, Hash
, Equal
>;
28 template <typename Container
, typename
... Args
>
29 void test_transparent_find(Args
&&... args
) {
30 Container c
{std::forward
<Args
>(args
)...};
32 assert(c
.find(SearchedType
<int>(1, &conversions
)) != c
.end());
33 assert(c
.find(SearchedType
<int>(2, &conversions
)) != c
.end());
34 assert(conversions
== 0);
35 assert(c
.find(SearchedType
<int>(3, &conversions
)) == c
.end());
36 assert(conversions
== 0);
39 template <typename Container
, typename
... Args
>
40 void test_non_transparent_find(Args
&&... args
) {
41 Container c
{std::forward
<Args
>(args
)...};
43 assert(c
.find(SearchedType
<int>(1, &conversions
)) != c
.end());
44 assert(conversions
> 0);
46 assert(c
.find(SearchedType
<int>(2, &conversions
)) != c
.end());
47 assert(conversions
> 0);
49 assert(c
.find(SearchedType
<int>(3, &conversions
)) == c
.end());
50 assert(conversions
> 0);
53 template <typename Container
, typename
... Args
>
54 void test_transparent_count(Args
&&... args
) {
55 Container c
{std::forward
<Args
>(args
)...};
57 assert(c
.count(SearchedType
<int>(1, &conversions
)) > 0);
58 assert(c
.count(SearchedType
<int>(2, &conversions
)) > 0);
59 assert(conversions
== 0);
60 assert(c
.count(SearchedType
<int>(3, &conversions
)) == 0);
61 assert(conversions
== 0);
64 template <typename Container
, typename
... Args
>
65 void test_non_transparent_count(Args
&&... args
) {
66 Container c
{std::forward
<Args
>(args
)...};
68 assert(c
.count(SearchedType
<int>(1, &conversions
)) > 0);
69 assert(conversions
> 0);
71 assert(c
.count(SearchedType
<int>(2, &conversions
)) > 0);
72 assert(conversions
> 0);
74 assert(c
.count(SearchedType
<int>(3, &conversions
)) == 0);
75 assert(conversions
> 0);
78 template <typename Container
, typename
... Args
>
79 void test_transparent_contains(Args
&&... args
) {
80 Container c
{std::forward
<Args
>(args
)...};
82 assert(c
.contains(SearchedType
<int>(1, &conversions
)));
83 assert(c
.contains(SearchedType
<int>(2, &conversions
)));
84 assert(conversions
== 0);
85 assert(!c
.contains(SearchedType
<int>(3, &conversions
)));
86 assert(conversions
== 0);
89 template <typename Container
, typename
... Args
>
90 void test_non_transparent_contains(Args
&&... args
) {
91 Container c
{std::forward
<Args
>(args
)...};
93 assert(c
.contains(SearchedType
<int>(1, &conversions
)));
94 assert(conversions
> 0);
96 assert(c
.contains(SearchedType
<int>(2, &conversions
)));
97 assert(conversions
> 0);
99 assert(!c
.contains(SearchedType
<int>(3, &conversions
)));
100 assert(conversions
> 0);
103 template <typename Container
, typename
... Args
>
104 void test_transparent_equal_range(Args
&&... args
) {
105 Container c
{std::forward
<Args
>(args
)...};
107 auto iters
= c
.equal_range(SearchedType
<int>(1, &conversions
));
108 assert(std::distance(iters
.first
, iters
.second
) > 0);
109 iters
= c
.equal_range(SearchedType
<int>(2, &conversions
));
110 assert(std::distance(iters
.first
, iters
.second
) > 0);
111 assert(conversions
== 0);
112 iters
= c
.equal_range(SearchedType
<int>(3, &conversions
));
113 assert(std::distance(iters
.first
, iters
.second
) == 0);
114 assert(conversions
== 0);
117 template <typename Container
, typename
... Args
>
118 void test_non_transparent_equal_range(Args
&&... args
) {
119 Container c
{std::forward
<Args
>(args
)...};
121 auto iters
= c
.equal_range(SearchedType
<int>(1, &conversions
));
122 assert(std::distance(iters
.first
, iters
.second
) > 0);
123 assert(conversions
> 0);
125 iters
= c
.equal_range(SearchedType
<int>(2, &conversions
));
126 assert(std::distance(iters
.first
, iters
.second
) > 0);
127 assert(conversions
> 0);
129 iters
= c
.equal_range(SearchedType
<int>(3, &conversions
));
130 assert(std::distance(iters
.first
, iters
.second
) == 0);
131 assert(conversions
> 0);
134 #endif // TEST_STD_VER > 17
136 #endif // TEST_TRANSPARENT_UNORDERED_H