1
2// Copyright 2008-2009 Daniel James.
3// Copyright 2022-2023 Christian Mazakas.
4// Distributed under the Boost Software License, Version 1.0. (See accompanying
5// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7// clang-format off
8#include "../helpers/prefix.hpp"
9#ifdef BOOST_UNORDERED_FOA_TESTS
10#include <boost/unordered/unordered_flat_set_fwd.hpp>
11#include <boost/unordered/unordered_node_set_fwd.hpp>
12#include <boost/unordered/detail/implementation.hpp>
13#else
14#include <boost/unordered/unordered_set_fwd.hpp>
15#endif
16#include "../helpers/postfix.hpp"
17// clang-format on
18
19struct true_type
20{
21 char x[100];
22};
23struct false_type
24{
25 char x;
26};
27
28false_type is_unordered_set_impl(void*);
29
30#ifdef BOOST_UNORDERED_FOA_TESTS
31template <class Value, class Hash, class Pred, class Alloc>
32true_type is_unordered_set_impl(
33 boost::unordered_flat_set<Value, Hash, Pred, Alloc>*);
34
35template <class Value, class Hash, class Pred, class Alloc>
36true_type is_unordered_set_impl(
37 boost::unordered_node_set<Value, Hash, Pred, Alloc>*);
38
39template <typename T>
40void call_swap(boost::unordered_flat_set<T>& x, boost::unordered_flat_set<T>& y)
41{
42 swap(x, y);
43}
44
45template <typename T>
46void call_swap(boost::unordered_node_set<T>& x, boost::unordered_node_set<T>& y)
47{
48 swap(x, y);
49}
50
51template <typename T>
52bool call_equals(
53 boost::unordered_flat_set<T>& x, boost::unordered_flat_set<T>& y)
54{
55 return x == y;
56}
57
58template <typename T>
59bool call_equals(
60 boost::unordered_node_set<T>& x, boost::unordered_node_set<T>& y)
61{
62 return x == y;
63}
64
65template <typename T>
66bool call_not_equals(
67 boost::unordered_flat_set<T>& x, boost::unordered_flat_set<T>& y)
68{
69 return x != y;
70}
71
72template <typename T>
73bool call_not_equals(
74 boost::unordered_node_set<T>& x, boost::unordered_node_set<T>& y)
75{
76 return x != y;
77}
78#else
79template <class Value, class Hash, class Pred, class Alloc>
80true_type is_unordered_set_impl(
81 boost::unordered_set<Value, Hash, Pred, Alloc>*);
82
83template <typename T>
84void call_swap(boost::unordered_set<T>& x, boost::unordered_set<T>& y)
85{
86 swap(x, y);
87}
88
89template <typename T>
90bool call_equals(boost::unordered_set<T>& x, boost::unordered_set<T>& y)
91{
92 return x == y;
93}
94
95template <typename T>
96bool call_not_equals(boost::unordered_set<T>& x, boost::unordered_set<T>& y)
97{
98 return x != y;
99}
100#endif
101
102#ifndef BOOST_UNORDERED_FOA_TESTS
103template <typename T>
104void call_swap(boost::unordered_multiset<T>& x, boost::unordered_multiset<T>& y)
105{
106 swap(x, y);
107}
108
109template <typename T>
110bool call_equals(
111 boost::unordered_multiset<T>& x, boost::unordered_multiset<T>& y)
112{
113 return x == y;
114}
115
116template <typename T>
117bool call_not_equals(
118 boost::unordered_multiset<T>& x, boost::unordered_multiset<T>& y)
119{
120 return x != y;
121}
122#endif
123
124#include "../helpers/test.hpp"
125
126#ifdef BOOST_UNORDERED_FOA_TESTS
127typedef boost::unordered_flat_set<int> int_set;
128typedef boost::unordered_node_set<int> int_node_set;
129#else
130typedef boost::unordered_set<int> int_set;
131typedef boost::unordered_multiset<int> int_multiset;
132#endif
133
134UNORDERED_AUTO_TEST (use_fwd_declared_trait_without_definition) {
135 BOOST_TEST(sizeof(is_unordered_set_impl((int_set*)0)) == sizeof(true_type));
136#ifdef BOOST_UNORDERED_FOA_TESTS
137 BOOST_TEST(
138 sizeof(is_unordered_set_impl((int_node_set*)0)) == sizeof(true_type));
139#endif
140}
141
142#ifdef BOOST_UNORDERED_FOA_TESTS
143#include <boost/unordered/unordered_flat_set.hpp>
144#include <boost/unordered/unordered_node_set.hpp>
145#else
146#include <boost/unordered_set.hpp>
147#endif
148
149UNORDERED_AUTO_TEST (use_fwd_declared_trait) {
150 int_set x;
151 BOOST_TEST(sizeof(is_unordered_set_impl(&x)) == sizeof(true_type));
152 BOOST_TEST(sizeof(is_unordered_set_impl((int*)0)) == sizeof(false_type));
153}
154
155#ifdef BOOST_UNORDERED_FOA_TESTS
156UNORDERED_AUTO_TEST (use_node_fwd_declared_trait) {
157 int_node_set x;
158 BOOST_TEST(sizeof(is_unordered_set_impl(&x)) == sizeof(true_type));
159 BOOST_TEST(sizeof(is_unordered_set_impl((int*)0)) == sizeof(false_type));
160}
161#endif
162
163UNORDERED_AUTO_TEST (use_set_fwd_declared_function) {
164 int_set x, y;
165 x.insert(x: 1);
166 y.insert(x: 2);
167 call_swap(x, y);
168
169 BOOST_TEST(y.find(1) != y.end());
170 BOOST_TEST(y.find(2) == y.end());
171
172 BOOST_TEST(x.find(1) == x.end());
173 BOOST_TEST(x.find(2) != x.end());
174
175 BOOST_TEST(!call_equals(x, y));
176 BOOST_TEST(call_not_equals(x, y));
177}
178
179#ifdef BOOST_UNORDERED_FOA_TESTS
180UNORDERED_AUTO_TEST (use_node_set_fwd_declared_function) {
181 int_node_set x, y;
182 x.insert(1);
183 y.insert(2);
184 call_swap(x, y);
185
186 BOOST_TEST(y.find(1) != y.end());
187 BOOST_TEST(y.find(2) == y.end());
188
189 BOOST_TEST(x.find(1) == x.end());
190 BOOST_TEST(x.find(2) != x.end());
191
192 BOOST_TEST(!call_equals(x, y));
193 BOOST_TEST(call_not_equals(x, y));
194}
195#endif
196
197#ifndef BOOST_UNORDERED_FOA_TESTS
198UNORDERED_AUTO_TEST (use_multiset_fwd_declared_function) {
199 int_multiset x, y;
200 call_swap(x, y);
201 BOOST_TEST(call_equals(x, y));
202 BOOST_TEST(!call_not_equals(x, y));
203}
204#endif
205
206RUN_TESTS()
207

source code of boost/libs/unordered/test/unordered/fwd_set_test.cpp