made f the last argument in all *_or_[c]visit functions

This commit is contained in:
joaquintides
2023-04-09 20:20:55 +02:00
parent 8544d9f3c8
commit 8a4e987030
3 changed files with 155 additions and 54 deletions

View File

@ -362,18 +362,20 @@ namespace boost {
return table_.emplace(std::forward<Args>(args)...); return table_.emplace(std::forward<Args>(args)...);
} }
template <class F, class... Args> template <class Arg, class... Args>
bool emplace_or_visit(F f, Args&&... args) bool emplace_or_visit(Arg&& arg, Args&&... args)
{ {
BOOST_UNORDERED_STATIC_ASSERT_INVOCABLE(F) //BOOST_UNORDERED_STATIC_ASSERT_INVOCABLE(F)
return table_.emplace_or_visit(f, std::forward<Args>(args)...); return table_.emplace_or_visit(
std::forward<Arg>(arg), std::forward<Args>(args)...);
} }
template <class F, class... Args> template <class Arg, class... Args>
bool emplace_or_cvisit(F f, Args&&... args) bool emplace_or_cvisit(Arg&& arg, Args&&... args)
{ {
BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F) //BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
return table_.emplace_or_cvisit(f, std::forward<Args>(args)...); return table_.emplace_or_cvisit(
std::forward<Arg>(arg), std::forward<Args>(args)...);
} }
template <class... Args> template <class... Args>
@ -396,50 +398,52 @@ namespace boost {
std::forward<K>(k), std::forward<Args>(args)...); std::forward<K>(k), std::forward<Args>(args)...);
} }
template <class F, class... Args> template <class Arg, class... Args>
bool try_emplace_or_visit(key_type const& k, F f, Args&&... args) bool try_emplace_or_visit(key_type const& k, Arg&& arg, Args&&... args)
{ {
BOOST_UNORDERED_STATIC_ASSERT_INVOCABLE(F) //BOOST_UNORDERED_STATIC_ASSERT_INVOCABLE(F)
return table_.try_emplace_or_visit(k, f, std::forward<Args>(args)...);
}
template <class F, class... Args>
bool try_emplace_or_cvisit(key_type const& k, F f, Args&&... args)
{
BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
return table_.try_emplace_or_cvisit(k, f, std::forward<Args>(args)...);
}
template <class F, class... Args>
bool try_emplace_or_visit(key_type&& k, F f, Args&&... args)
{
BOOST_UNORDERED_STATIC_ASSERT_INVOCABLE(F)
return table_.try_emplace_or_visit( return table_.try_emplace_or_visit(
std::move(k), f, std::forward<Args>(args)...); k, std::forward<Arg>(arg), std::forward<Args>(args)...);
} }
template <class F, class... Args> template <class Arg, class... Args>
bool try_emplace_or_cvisit(key_type&& k, F f, Args&&... args) bool try_emplace_or_cvisit(key_type const& k, Arg&& arg, Args&&... args)
{ {
BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F) //BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
return table_.try_emplace_or_cvisit( return table_.try_emplace_or_cvisit(
std::move(k), f, std::forward<Args>(args)...); k, std::forward<Arg>(arg), std::forward<Args>(args)...);
} }
template <class K, class F, class... Args> template <class Arg, class... Args>
bool try_emplace_or_visit(K&& k, F f, Args&&... args) bool try_emplace_or_visit(key_type&& k, Arg&& arg, Args&&... args)
{ {
BOOST_UNORDERED_STATIC_ASSERT_INVOCABLE(F) //BOOST_UNORDERED_STATIC_ASSERT_INVOCABLE(F)
return table_.try_emplace_or_visit( return table_.try_emplace_or_visit(
std::forward<K>(k), f, std::forward<Args>(args)...); std::move(k), std::forward<Arg>(arg), std::forward<Args>(args)...);
} }
template <class K, class F, class... Args> template <class Arg, class... Args>
bool try_emplace_or_cvisit(K&& k, F f, Args&&... args) bool try_emplace_or_cvisit(key_type&& k, Arg&& arg, Args&&... args)
{ {
BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F) //BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
return table_.try_emplace_or_cvisit( return table_.try_emplace_or_cvisit(
std::forward<K>(k), f, std::forward<Args>(args)...); std::move(k), std::forward<Arg>(arg), std::forward<Args>(args)...);
}
template <class K, class Arg, class... Args>
bool try_emplace_or_visit(K&& k, Arg&& arg, Args&&... args)
{
//BOOST_UNORDERED_STATIC_ASSERT_INVOCABLE(F)
return table_.try_emplace_or_visit(
std::forward<K>(k), std::forward<Arg>(arg), std::forward<Args>(args)...);
}
template <class K, class Arg, class... Args>
bool try_emplace_or_cvisit(K&& k, Arg&& arg, Args&&... args)
{
//BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
return table_.try_emplace_or_cvisit(
std::forward<K>(k), std::forward<Arg>(arg), std::forward<Args>(args)...);
} }
size_type erase(key_type const& k) { return table_.erase(k); } size_type erase(key_type const& k) { return table_.erase(k); }

View File

@ -17,13 +17,16 @@
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/core/no_exceptions_support.hpp> #include <boost/core/no_exceptions_support.hpp>
#include <boost/cstdint.hpp> #include <boost/cstdint.hpp>
#include <boost/mp11/tuple.hpp>
#include <boost/unordered/detail/foa/core.hpp> #include <boost/unordered/detail/foa/core.hpp>
#include <boost/unordered/detail/foa/rw_spinlock.hpp> #include <boost/unordered/detail/foa/rw_spinlock.hpp>
#include <boost/unordered/detail/foa/tuple_rotate_right.hpp>
#include <cstddef> #include <cstddef>
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <new> #include <new>
#include <type_traits> #include <type_traits>
#include <tuple>
#include <utility> #include <utility>
#if !defined(BOOST_UNORDERED_DISABLE_PARALLEL_ALGORITHMS) #if !defined(BOOST_UNORDERED_DISABLE_PARALLEL_ALGORITHMS)
@ -445,34 +448,34 @@ public:
try_emplace_args_t{},std::forward<Key>(x),std::forward<Args>(args)...); try_emplace_args_t{},std::forward<Key>(x),std::forward<Args>(args)...);
} }
template<typename Key,typename F,typename... Args> template<typename Key,typename... Args>
BOOST_FORCEINLINE bool try_emplace_or_visit(Key&& x,F&& f,Args&&... args) BOOST_FORCEINLINE bool try_emplace_or_visit(Key&& x,Args&&... args)
{ {
return emplace_or_visit_impl( return emplace_or_visit_flast(
group_exclusive{},std::forward<F>(f), group_exclusive{},
try_emplace_args_t{},std::forward<Key>(x),std::forward<Args>(args)...); try_emplace_args_t{},std::forward<Key>(x),std::forward<Args>(args)...);
} }
template<typename Key,typename F,typename... Args> template<typename Key,typename... Args>
BOOST_FORCEINLINE bool try_emplace_or_cvisit(Key&& x,F&& f,Args&&... args) BOOST_FORCEINLINE bool try_emplace_or_cvisit(Key&& x,Args&&... args)
{ {
return emplace_or_visit_impl( return emplace_or_visit_flast(
group_shared{},std::forward<F>(f), group_shared{},
try_emplace_args_t{},std::forward<Key>(x),std::forward<Args>(args)...); try_emplace_args_t{},std::forward<Key>(x),std::forward<Args>(args)...);
} }
template<typename F,typename... Args> template<typename... Args>
BOOST_FORCEINLINE bool emplace_or_visit(F&& f,Args&&... args) BOOST_FORCEINLINE bool emplace_or_visit(Args&&... args)
{ {
return construct_and_emplace_or_visit( return construct_and_emplace_or_visit_flast(
group_exclusive{},std::forward<F>(f),std::forward<Args>(args)...); group_exclusive{},std::forward<Args>(args)...);
} }
template<typename F,typename... Args> template<typename... Args>
BOOST_FORCEINLINE bool emplace_or_cvisit(F&& f,Args&&... args) BOOST_FORCEINLINE bool emplace_or_cvisit(Args&&... args)
{ {
return construct_and_emplace_or_visit( return construct_and_emplace_or_visit_flast(
group_shared{},std::forward<F>(f),std::forward<Args>(args)...); group_shared{},std::forward<Args>(args)...);
} }
template<typename F> template<typename F>
@ -880,6 +883,30 @@ private:
group_shared{},[](const value_type&){},std::forward<Args>(args)...); group_shared{},[](const value_type&){},std::forward<Args>(args)...);
} }
struct call_construct_and_emplace_or_visit
{
template<typename... Args>
BOOST_FORCEINLINE bool operator()(
concurrent_table* this_,Args&&... args)const
{
return this_->construct_and_emplace_or_visit(
std::forward<Args>(args)...);
}
};
template<typename GroupAccessMode,typename... Args>
BOOST_FORCEINLINE bool construct_and_emplace_or_visit_flast(
GroupAccessMode access_mode,Args&&... args)
{
return mp11::tuple_apply(
call_construct_and_emplace_or_visit{},
std::tuple_cat(
std::make_tuple(this,access_mode),
tuple_rotate_right(std::forward_as_tuple(std::forward<Args>(args)...))
)
);
}
template<typename GroupAccessMode,typename F,typename... Args> template<typename GroupAccessMode,typename F,typename... Args>
BOOST_FORCEINLINE bool construct_and_emplace_or_visit( BOOST_FORCEINLINE bool construct_and_emplace_or_visit(
GroupAccessMode access_mode,F&& f,Args&&... args) GroupAccessMode access_mode,F&& f,Args&&... args)
@ -914,6 +941,29 @@ private:
access_mode,std::forward<F>(f),std::forward<Args>(args)...); access_mode,std::forward<F>(f),std::forward<Args>(args)...);
} }
struct call_emplace_or_visit_impl
{
template<typename... Args>
BOOST_FORCEINLINE bool operator()(
concurrent_table* this_,Args&&... args)const
{
return this_->emplace_or_visit_impl(std::forward<Args>(args)...);
}
};
template<typename GroupAccessMode,typename... Args>
BOOST_FORCEINLINE bool emplace_or_visit_flast(
GroupAccessMode access_mode,Args&&... args)
{
return mp11::tuple_apply(
call_emplace_or_visit_impl{},
std::tuple_cat(
std::make_tuple(this,access_mode),
tuple_rotate_right(std::forward_as_tuple(std::forward<Args>(args)...))
)
);
}
template<typename GroupAccessMode,typename F,typename... Args> template<typename GroupAccessMode,typename F,typename... Args>
BOOST_FORCEINLINE bool emplace_or_visit_impl( BOOST_FORCEINLINE bool emplace_or_visit_impl(
GroupAccessMode access_mode,F&& f,Args&&... args) GroupAccessMode access_mode,F&& f,Args&&... args)

View File

@ -0,0 +1,47 @@
/* Copyright 2023 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)
*
* See https://www.boost.org/libs/unordered for library home page.
*/
#ifndef BOOST_UNORDERED_DETAIL_FOA_TUPLE_ROTATE_RIGHT_HPP
#define BOOST_UNORDERED_DETAIL_FOA_TUPLE_ROTATE_RIGHT_HPP
#include <boost/mp11/integer_sequence.hpp>
#include <tuple>
#include <utility>
namespace boost{
namespace unordered{
namespace detail{
namespace foa{
template<std::size_t... Is,typename Tuple>
auto tuple_rotate_right_aux(mp11::index_sequence<Is...>,Tuple&& x)
->std::tuple<decltype(
std::get<(Is+sizeof...(Is)-1)%sizeof...(Is)>(std::forward<Tuple>(x)))...
>
{
return {
std::get<(Is+sizeof...(Is)-1)%sizeof...(Is)>(std::forward<Tuple>(x))...};
}
template<typename Tuple>
auto tuple_rotate_right(Tuple&& x)
->decltype(tuple_rotate_right_aux(
mp11::make_index_sequence<std::tuple_size<Tuple>::value>{},
std::forward<Tuple>(x)))
{
return tuple_rotate_right_aux(
mp11::make_index_sequence<std::tuple_size<Tuple>::value>{},
std::forward<Tuple>(x));
}
} /* namespace foa */
} /* namespace detail */
} /* namespace unordered */
} /* namespace boost */
#endif