diff --git a/include/boost/unordered/detail/foa/concurrent_table.hpp b/include/boost/unordered/detail/foa/concurrent_table.hpp index bcece6af..2461bbad 100644 --- a/include/boost/unordered/detail/foa/concurrent_table.hpp +++ b/include/boost/unordered/detail/foa/concurrent_table.hpp @@ -41,6 +41,23 @@ namespace boost{ namespace unordered{ namespace detail{ + +#if defined(BOOST_UNORDERED_PARALLEL_ALGORITHMS) + +template +using is_execution_policy=std::is_execution_policy< + typename std::remove_cv< + typename std::remove_reference::type + >::type +>; + +#else + +template +using is_execution_policy=std::false_type; + +#endif + namespace foa{ #if defined(BOOST_MSVC) @@ -277,18 +294,6 @@ class concurrent_table: using super::N; using prober=typename super::prober; -#if defined(BOOST_UNORDERED_PARALLEL_ALGORITHMS) - template - using is_execution_policy=std::is_execution_policy< - typename std::remove_cv< - typename std::remove_reference::type - >::type - >; -#else - template - using is_execution_policy=std::false_type; -#endif - public: using key_type=typename super::key_type; using init_type=typename super::init_type; @@ -1060,7 +1065,7 @@ private: last=first+this->arrays.groups_size_mask+1; std::for_each(std::forward(policy),first,last, [&,this](group_type& g){ - std::size_t pos=&g-first; + std::size_t pos=static_cast(&g-first); auto p=this->arrays.elements+pos*N; auto lck=access(access_mode,pos); auto mask=this->match_really_occupied(&g,last); diff --git a/test/cfoa/erase_tests.cpp b/test/cfoa/erase_tests.cpp index fdcc1833..2066e07e 100644 --- a/test/cfoa/erase_tests.cpp +++ b/test/cfoa/erase_tests.cpp @@ -245,6 +245,63 @@ namespace { } } erase_if; + struct erase_if_exec_policy_type + { + template void operator()(std::vector& values, X& x) + { +#if defined(BOOST_UNORDERED_PARALLEL_ALGORITHMS) + using value_type = typename X::value_type; + + std::atomic num_invokes{0}; + + auto const old_size = x.size(); + + auto const old_dc = +raii::default_constructor; + auto const old_cc = +raii::copy_constructor; + auto const old_mc = +raii::move_constructor; + + auto const old_d = +raii::destructor; + + auto max = 0; + x.visit_all([&max](value_type const& v) { + if (v.second.x_ > max) { + max = v.second.x_; + } + }); + + auto threshold = max / 2; + + auto expected_erasures = 0u; + x.visit_all([&expected_erasures, threshold](value_type const& v) { + if (v.second.x_ > threshold) { + ++expected_erasures; + } + }); + + thread_runner(values, [&num_invokes, &x, threshold](boost::span s) { + (void)s; + x.erase_if( + std::execution::par_unseq, [&num_invokes, threshold](value_type& v) { + ++num_invokes; + return v.second.x_ > threshold; + }); + }); + + BOOST_TEST_GE(+num_invokes, old_size); + BOOST_TEST_LE(+num_invokes, old_size * num_threads); + + BOOST_TEST_EQ(raii::default_constructor, old_dc); + BOOST_TEST_EQ(raii::copy_constructor, old_cc); + BOOST_TEST_EQ(raii::move_constructor, old_mc); + + BOOST_TEST_EQ(raii::destructor, old_d + 2 * expected_erasures); +#else + (void)values; + (void)x; +#endif + } + } erase_if_exec_policy; + template void erase(X*, G gen, F eraser, test::random_generator rg) { @@ -296,14 +353,14 @@ UNORDERED_TEST( erase, ((map)) ((value_type_generator)(init_type_generator)) - ((lvalue_eraser)(lvalue_eraser_if)(erase_if)) + ((lvalue_eraser)(lvalue_eraser_if)(erase_if)(erase_if_exec_policy)) ((default_generator)(sequential)(limited_range))) UNORDERED_TEST( erase, ((transparent_map)) ((value_type_generator)(init_type_generator)) - ((transp_lvalue_eraser)(transp_lvalue_eraser_if)) + ((transp_lvalue_eraser)(transp_lvalue_eraser_if)(erase_if_exec_policy)) ((default_generator)(sequential)(limited_range))) // clang-format on