1// Copyright (C) 2023 Christian Mazakas
2// Copyright (C) 2023 Joaquin M Lopez Munoz
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
6#include "helpers.hpp"
7#include <boost/config/workaround.hpp>
8#include <boost/unordered/concurrent_flat_map_fwd.hpp>
9#include <boost/unordered/concurrent_flat_set_fwd.hpp>
10#include <limits>
11
12test::seed_t initialize_seed{32304628};
13
14using test::default_generator;
15using test::limited_range;
16using test::sequential;
17
18template <class T>
19void swap_call(boost::unordered::concurrent_flat_map<T, T>& x1,
20 boost::unordered::concurrent_flat_map<T, T>& x2)
21{
22 swap(x1, x2);
23}
24
25template <class T>
26bool equal_call(boost::unordered::concurrent_flat_map<T, T>& x1,
27 boost::unordered::concurrent_flat_map<T, T>& x2)
28{
29 return x1 == x2;
30}
31
32template <class T>
33bool unequal_call(boost::unordered::concurrent_flat_map<T, T>& x1,
34 boost::unordered::concurrent_flat_map<T, T>& x2)
35{
36 return x1 != x2;
37}
38
39template <class T>
40void swap_call(boost::unordered::concurrent_flat_set<T>& x1,
41 boost::unordered::concurrent_flat_set<T>& x2)
42{
43 swap(x1, x2);
44}
45
46template <class T>
47bool equal_call(boost::unordered::concurrent_flat_set<T>& x1,
48 boost::unordered::concurrent_flat_set<T>& x2)
49{
50 return x1 == x2;
51}
52
53template <class T>
54bool unequal_call(boost::unordered::concurrent_flat_set<T>& x1,
55 boost::unordered::concurrent_flat_set<T>& x2)
56{
57 return x1 != x2;
58}
59
60#include <boost/unordered/concurrent_flat_map.hpp>
61#include <boost/unordered/concurrent_flat_set.hpp>
62
63using map_type = boost::unordered::concurrent_flat_map<int, int>;
64using set_type = boost::unordered::concurrent_flat_map<int, int>;
65
66map_type* test_map;
67set_type* test_set;
68
69template <typename X>
70void fwd_swap_call(X*)
71{
72#if !defined(BOOST_CLANG_VERSION) || \
73 BOOST_WORKAROUND(BOOST_CLANG_VERSION, < 30700) || \
74 BOOST_WORKAROUND(BOOST_CLANG_VERSION, >= 30800)
75// clang-3.7 seems to have a codegen bug here so we workaround it
76
77 X x1, x2;
78 swap_call(x1, x2);
79#endif
80}
81
82template <typename X>
83void fwd_equal_call(X*)
84{
85 X x1, x2;
86 BOOST_TEST(equal_call(x1, x2));
87}
88
89template <typename X>
90void fwd_unequal_call(X*)
91{
92 X x1, x2;
93 BOOST_TEST_NOT(unequal_call(x1, x2));
94}
95
96// this isn't the best place for this test but it's better than introducing a
97// new file
98template <typename X>
99void max_size(X*)
100{
101 X x1;
102 BOOST_TEST_EQ(
103 x1.max_size(), std::numeric_limits<typename X::size_type>::max());
104}
105
106// clang-format off
107UNORDERED_TEST(
108 fwd_swap_call,
109 ((test_map)(test_set)))
110
111UNORDERED_TEST(
112 fwd_equal_call,
113 ((test_map)(test_set)))
114
115UNORDERED_TEST(
116 fwd_unequal_call,
117 ((test_map)(test_set)))
118
119UNORDERED_TEST(
120 max_size,
121 ((test_map)(test_set)))
122// clang-format on
123
124RUN_TESTS()
125

source code of boost/libs/unordered/test/cfoa/fwd_tests.cpp