Skip to content

Commit

Permalink
Enable forwards of non-std functions
Browse files Browse the repository at this point in the history
  • Loading branch information
alugowski committed Dec 7, 2023
1 parent 1047616 commit 379833c
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions include/poolstl/seq_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
* Forward poolstl::seq to the native sequential (no policy) method.
*/

#define POOLSTL_DEFINE_SEQ_FWD(FNAME) \
#define POOLSTL_DEFINE_SEQ_FWD(NS, FNAME) \
template<class EP, typename...ARGS> \
auto FNAME(EP&&, ARGS&&...args) -> \
poolstl::internal::enable_if_seq<EP, decltype(std::FNAME(std::forward<ARGS>(args)...))> { \
return std::FNAME(std::forward<ARGS>(args)...); \
poolstl::internal::enable_if_seq<EP, decltype(NS::FNAME(std::forward<ARGS>(args)...))> { \
return NS::FNAME(std::forward<ARGS>(args)...); \
}

#define POOLSTL_DEFINE_SEQ_FWD_VOID(FNAME) \
#define POOLSTL_DEFINE_SEQ_FWD_VOID(NS, FNAME) \
template<class EP, typename...ARGS> \
poolstl::internal::enable_if_seq<EP, void> FNAME(EP&&, ARGS&&... args) { \
std::FNAME(std::forward<ARGS>(args)...); \
NS::FNAME(std::forward<ARGS>(args)...); \
}

#if POOLSTL_HAVE_CXX17
Expand All @@ -32,63 +32,63 @@
* Useful to choose between parallel and sequential policies at runtime via par_if.
*/

#define POOLSTL_DEFINE_PAR_IF_FWD_VOID(FNAME) \
#define POOLSTL_DEFINE_PAR_IF_FWD_VOID(NS, FNAME) \
template<class EP, typename...ARGS> \
poolstl::internal::enable_if_poolstl_variant<EP, void> FNAME(EP&& policy, ARGS&&...args) { \
std::visit([&](auto&& pol) { std::FNAME(pol, std::forward<ARGS>(args)...); }, policy.var); \
std::visit([&](auto&& pol) { NS::FNAME(pol, std::forward<ARGS>(args)...); }, policy.var); \
}

#define POOLSTL_DEFINE_PAR_IF_FWD(FNAME) \
#define POOLSTL_DEFINE_PAR_IF_FWD(NS, FNAME) \
template<class EP, typename...ARGS> \
auto FNAME(EP&& policy, ARGS&&...args) -> \
poolstl::internal::enable_if_poolstl_variant<EP, decltype(std::FNAME(std::forward<ARGS>(args)...))> { \
return std::visit([&](auto&& pol) { return std::FNAME(pol, std::forward<ARGS>(args)...); }, policy.var); \
poolstl::internal::enable_if_poolstl_variant<EP, decltype(NS::FNAME(std::forward<ARGS>(args)...))> { \
return std::visit([&](auto&& pol) { return NS::FNAME(pol, std::forward<ARGS>(args)...); }, policy.var); \
}

#else
#define POOLSTL_DEFINE_PAR_IF_FWD_VOID(FNAME)
#define POOLSTL_DEFINE_PAR_IF_FWD(FNAME)
#define POOLSTL_DEFINE_PAR_IF_FWD_VOID(NS, FNAME)
#define POOLSTL_DEFINE_PAR_IF_FWD(NS, FNAME)
#endif
/*
* Define both the sequential forward and dynamic chooser.
*/
#define POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(FNAME) \
POOLSTL_DEFINE_SEQ_FWD(FNAME) \
POOLSTL_DEFINE_PAR_IF_FWD(FNAME)
#define POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(NS, FNAME) \
POOLSTL_DEFINE_SEQ_FWD(NS, FNAME) \
POOLSTL_DEFINE_PAR_IF_FWD(NS, FNAME)

#define POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF_VOID(FNAME) \
POOLSTL_DEFINE_SEQ_FWD_VOID(FNAME) \
POOLSTL_DEFINE_PAR_IF_FWD_VOID(FNAME)
#define POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF_VOID(NS, FNAME) \
POOLSTL_DEFINE_SEQ_FWD_VOID(NS, FNAME) \
POOLSTL_DEFINE_PAR_IF_FWD_VOID(NS, FNAME)

namespace std {
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(all_of)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(any_of)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(none_of)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(std, all_of)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(std, any_of)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(std, none_of)

POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(count)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(count_if)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(std, count)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(std, count_if)

POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(copy)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(copy_n)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(std, copy)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(std, copy_n)

POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF_VOID(fill)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(fill_n)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF_VOID(std, fill)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(std, fill_n)

POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(find)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(find_if)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(find_if_not)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(std, find)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(std, find_if)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(std, find_if_not)

POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF_VOID(for_each)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF_VOID(std, for_each)
#if POOLSTL_HAVE_CXX17_LIB
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(for_each_n)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(std, for_each_n)
#endif

POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(transform)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(std, transform)

#if POOLSTL_HAVE_CXX17_LIB
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(exclusive_scan)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(reduce)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(transform_reduce)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(std, exclusive_scan)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(std, reduce)
POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF(std, transform_reduce)
#endif
}

Expand Down

0 comments on commit 379833c

Please sign in to comment.