66#ifndef POOLSTL_VARIANT_POLICY_HPP
77#define POOLSTL_VARIANT_POLICY_HPP
88
9- #include " execution "
10-
9+ #include < algorithm >
10+ # include < numeric >
1111#include < variant>
1212
13+ #if (__cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)) && \
14+ (!defined (_GLIBCXX_RELEASE) || _GLIBCXX_RELEASE >= 9 )
15+ #define POOLSTL_VARIANT_HAVE_CXX17_LIB 1
16+ #else
17+ #define POOLSTL_VARIANT_HAVE_CXX17_LIB 0
18+ #endif
19+
1320namespace poolstl {
1421 namespace execution {
1522 /* *
@@ -24,9 +31,12 @@ namespace poolstl {
2431 };
2532
2633 namespace internal {
34+ // Example variant definition
35+ /*
2736 using poolstl_policy_variant = std::variant<
2837 poolstl::execution::parallel_policy,
2938 poolstl::execution::sequenced_policy>;
39+ */
3040 }
3141 }
3242
@@ -52,25 +62,6 @@ namespace poolstl {
5262 }
5363}
5464
55- /*
56- * Forward poolstl::seq to the native sequential (no policy) method.
57- */
58-
59- #define POOLSTL_DEFINE_SEQ_FWD (NS, FNAME ) \
60- template <class EP , typename ...ARGS> \
61- auto FNAME (EP&&, ARGS&&...args) -> \
62- poolstl::internal::enable_if_seq<EP, decltype(NS::FNAME(std::forward<ARGS>(args)...))> { \
63- return NS::FNAME (std::forward<ARGS>(args)...); \
64- }
65-
66- #define POOLSTL_DEFINE_SEQ_FWD_VOID (NS, FNAME ) \
67- template <class EP , typename ...ARGS> \
68- poolstl::internal::enable_if_seq<EP, void > FNAME (EP&&, ARGS&&... args) { \
69- NS::FNAME (std::forward<ARGS>(args)...); \
70- }
71-
72- #if POOLSTL_HAVE_CXX17
73-
7465/*
7566 * Dynamically choose policy from a std::variant.
7667 * Useful to choose between parallel and sequential policies at runtime via par_if.
@@ -89,55 +80,48 @@ namespace poolstl {
8980 return std::visit ([&](auto && pol) { return NS::FNAME (pol, std::forward<ARGS>(args)...); }, policy.var ); \
9081 }
9182
92- #else
93- #define POOLSTL_DEFINE_PAR_IF_FWD_VOID (NS, FNAME )
94- #define POOLSTL_DEFINE_PAR_IF_FWD (NS, FNAME )
95- #endif
96- /*
97- * Define both the sequential forward and dynamic chooser.
98- */
99- #define POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF (NS, FNAME ) \
100- POOLSTL_DEFINE_SEQ_FWD (NS, FNAME) \
101- POOLSTL_DEFINE_PAR_IF_FWD(NS, FNAME)
102-
103- #define POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF_VOID (NS, FNAME ) \
104- POOLSTL_DEFINE_SEQ_FWD_VOID (NS, FNAME) \
105- POOLSTL_DEFINE_PAR_IF_FWD_VOID(NS, FNAME)
106-
10783namespace std {
108- POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF (std, all_of)
109- POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF (std, any_of)
110- POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF (std, none_of)
84+ // <algorithm>
85+
86+ POOLSTL_DEFINE_PAR_IF_FWD (std, all_of)
87+ POOLSTL_DEFINE_PAR_IF_FWD (std, any_of)
88+ POOLSTL_DEFINE_PAR_IF_FWD (std, none_of)
11189
112- POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF (std, count)
113- POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF (std, count_if)
90+ POOLSTL_DEFINE_PAR_IF_FWD (std, count)
91+ POOLSTL_DEFINE_PAR_IF_FWD (std, count_if)
11492
115- POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF (std, copy)
116- POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF (std, copy_n)
93+ POOLSTL_DEFINE_PAR_IF_FWD (std, copy)
94+ POOLSTL_DEFINE_PAR_IF_FWD (std, copy_n)
11795
118- POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF_VOID (std, fill)
119- POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF (std, fill_n)
96+ POOLSTL_DEFINE_PAR_IF_FWD_VOID (std, fill)
97+ POOLSTL_DEFINE_PAR_IF_FWD (std, fill_n)
12098
121- POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF (std, find)
122- POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF (std, find_if)
123- POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF (std, find_if_not)
99+ POOLSTL_DEFINE_PAR_IF_FWD (std, find)
100+ POOLSTL_DEFINE_PAR_IF_FWD (std, find_if)
101+ POOLSTL_DEFINE_PAR_IF_FWD (std, find_if_not)
124102
125- POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF_VOID (std, for_each)
126- #if POOLSTL_HAVE_CXX17_LIB
127- POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF (std, for_each_n)
103+ POOLSTL_DEFINE_PAR_IF_FWD_VOID (std, for_each)
104+ #if POOLSTL_VARIANT_HAVE_CXX17_LIB
105+ POOLSTL_DEFINE_PAR_IF_FWD (std, for_each_n)
128106#endif
129107
130- POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF (std, transform)
108+ POOLSTL_DEFINE_PAR_IF_FWD (std, transform)
109+
110+ // <numeric>
131111
132- #if POOLSTL_HAVE_CXX17_LIB
133- POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF (std, exclusive_scan)
134- POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF (std, reduce)
135- POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF (std, transform_reduce)
112+ #if POOLSTL_VARIANT_HAVE_CXX17_LIB
113+ POOLSTL_DEFINE_PAR_IF_FWD (std, exclusive_scan)
114+ POOLSTL_DEFINE_PAR_IF_FWD (std, reduce)
115+ POOLSTL_DEFINE_PAR_IF_FWD (std, transform_reduce)
136116#endif
137117}
138118
119+ #ifdef POOLSTL_VERSION_MAJOR
139120namespace poolstl {
140- POOLSTL_DEFINE_BOTH_SEQ_FWD_AND_PAR_IF_VOID (poolstl, for_each_chunk)
121+ // <poolstl/algorithm>
122+
123+ POOLSTL_DEFINE_PAR_IF_FWD_VOID (poolstl, for_each_chunk)
141124}
125+ #endif
142126
143127#endif
0 commit comments