| 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 | |
| 12 | test::seed_t initialize_seed{32304628}; |
| 13 | |
| 14 | using test::default_generator; |
| 15 | using test::limited_range; |
| 16 | using test::sequential; |
| 17 | |
| 18 | template <class T> |
| 19 | void 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 | |
| 25 | template <class T> |
| 26 | bool 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 | |
| 32 | template <class T> |
| 33 | bool 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 | |
| 39 | template <class T> |
| 40 | void swap_call(boost::unordered::concurrent_flat_set<T>& x1, |
| 41 | boost::unordered::concurrent_flat_set<T>& x2) |
| 42 | { |
| 43 | swap(x1, x2); |
| 44 | } |
| 45 | |
| 46 | template <class T> |
| 47 | bool equal_call(boost::unordered::concurrent_flat_set<T>& x1, |
| 48 | boost::unordered::concurrent_flat_set<T>& x2) |
| 49 | { |
| 50 | return x1 == x2; |
| 51 | } |
| 52 | |
| 53 | template <class T> |
| 54 | bool 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 | |
| 63 | using map_type = boost::unordered::concurrent_flat_map<int, int>; |
| 64 | using set_type = boost::unordered::concurrent_flat_map<int, int>; |
| 65 | |
| 66 | map_type* test_map; |
| 67 | set_type* test_set; |
| 68 | |
| 69 | template <typename X> |
| 70 | void 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 | |
| 82 | template <typename X> |
| 83 | void fwd_equal_call(X*) |
| 84 | { |
| 85 | X x1, x2; |
| 86 | BOOST_TEST(equal_call(x1, x2)); |
| 87 | } |
| 88 | |
| 89 | template <typename X> |
| 90 | void 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 |
| 98 | template <typename X> |
| 99 | void 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 |
| 107 | UNORDERED_TEST( |
| 108 | fwd_swap_call, |
| 109 | ((test_map)(test_set))) |
| 110 | |
| 111 | UNORDERED_TEST( |
| 112 | fwd_equal_call, |
| 113 | ((test_map)(test_set))) |
| 114 | |
| 115 | UNORDERED_TEST( |
| 116 | fwd_unequal_call, |
| 117 | ((test_map)(test_set))) |
| 118 | |
| 119 | UNORDERED_TEST( |
| 120 | max_size, |
| 121 | ((test_map)(test_set))) |
| 122 | // clang-format on |
| 123 | |
| 124 | RUN_TESTS() |
| 125 | |