// Copyright (C) 2023 Christian Mazakas // Copyright (C) 2023-2024 Joaquin M Lopez Munoz // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_UNORDERED_TEST_CFOA_COMMON_HELPERS_HPP #define BOOST_UNORDERED_TEST_CFOA_COMMON_HELPERS_HPP #include #include #include #include #include #include #include #include #include #include #include template struct value_cardinality { static constexpr std::size_t value=1; }; template struct value_cardinality > { static constexpr std::size_t value=2; }; template struct value_nonconst_cardinality { static constexpr std::size_t value=1; }; template struct value_nonconst_cardinality > { static constexpr std::size_t value= 1 * !std::is_const::value + 1 * !std::is_const::value ; }; template struct is_container_node_based: std::false_type {}; template struct is_container_node_based > : std::true_type {}; template struct is_container_node_based > : std::true_type {}; template struct reference_container_impl; template using reference_container = typename reference_container_impl::type; template struct reference_container_impl > { using type = boost::unordered_flat_map; }; template struct reference_container_impl > { using type = boost::unordered_node_map; }; template struct reference_container_impl > { using type = boost::unordered_flat_set; }; template struct reference_container_impl > { using type = boost::unordered_node_set; }; template struct nonconcurrent_container_impl; template using nonconcurrent_container = typename nonconcurrent_container_impl::type; template struct nonconcurrent_container_impl > { using type = boost::unordered_flat_map; }; template struct nonconcurrent_container_impl > { using type = boost::unordered_node_map; }; template struct nonconcurrent_container_impl > { using type = boost::unordered_flat_set; }; template struct nonconcurrent_container_impl > { using type = boost::unordered_node_set; }; template class Allocator> struct replace_allocator_impl; template class Allocator> using replace_allocator = typename replace_allocator_impl::type; template < typename K, typename V, typename H, typename P, typename A, template class Allocator > struct replace_allocator_impl< boost::concurrent_flat_map, Allocator> { using value_type = typename boost::concurrent_flat_map::value_type; using type = boost::concurrent_flat_map >; }; template < typename K, typename H, typename P, typename A, template class Allocator > struct replace_allocator_impl< boost::concurrent_flat_set, Allocator> { using value_type = typename boost::concurrent_flat_set::value_type; using type = boost::concurrent_flat_set >; }; template < typename K, typename V, typename H, typename P, typename A, template class Allocator > struct replace_allocator_impl< boost::concurrent_node_map, Allocator> { using value_type = typename boost::concurrent_node_map::value_type; using type = boost::concurrent_node_map >; }; template < typename K, typename H, typename P, typename A, template class Allocator > struct replace_allocator_impl< boost::concurrent_node_set, Allocator> { using value_type = typename boost::concurrent_node_set::value_type; using type = boost::concurrent_node_set >; }; template K const& get_key(K const& x) { return x; } template K const& get_key(const std::pair& x) { return x.first; } template K const& get_value(K const& x) { return x; } template V const& get_value(const std::pair& x) { return x.second; } template V& get_value(std::pair& x) { return x.second; } template void test_matches_reference(X const& x, Y const& reference_cont) { using value_type = typename X::value_type; BOOST_TEST_EQ(x.size(), x.visit_all([&](value_type const& v) { BOOST_TEST(reference_cont.contains(get_key(v))); BOOST_TEST_EQ(v, *reference_cont.find(get_key(v))); })); } template void test_fuzzy_matches_reference( X const& x, Y const& reference_cont, test::random_generator rg) { using value_type = typename X::value_type; BOOST_TEST_EQ(x.size(), x.visit_all([&](value_type const& v) { BOOST_TEST(reference_cont.contains(get_key(v))); if (rg == test::sequential) { BOOST_TEST_EQ(v, *reference_cont.find(get_key(v))); } })); } #endif // BOOST_UNORDERED_TEST_CFOA_COMMON_HELPERS_HPP