Skip to content
Snippets Groups Projects
Commit a11c842c authored by Tobias Leibner's avatar Tobias Leibner
Browse files

[common.numeric] use perfect forwarding

parent 77ca412b
No related branches found
No related tags found
1 merge request!9Fix reduce
Pipeline #57547 canceled
...@@ -25,43 +25,23 @@ namespace XT { ...@@ -25,43 +25,23 @@ namespace XT {
namespace Common { namespace Common {
template <class InputIt, class T> template <class... Args>
T reduce(InputIt first, InputIt last, T init) decltype(auto) reduce(Args&&... args)
{ {
#if CPP17_PARALLELISM_TS_SUPPORTED #if CPP17_PARALLELISM_TS_SUPPORTED
return std::reduce(first, last, init); return std::reduce(std::forward<Args>(args)...);
#else #else
return std::accumulate(first, last, init); return std::accumulate(std::forward<Args>(args)...);
#endif #endif
} }
template <class InputIt, class T, class BinaryOp> template <class... Args>
T reduce(InputIt first, InputIt last, T init, BinaryOp binary_op) decltype(auto) transform_reduce(Args&&... args)
{ {
#if CPP17_PARALLELISM_TS_SUPPORTED #if CPP17_PARALLELISM_TS_SUPPORTED
return std::reduce(first, last, init, binary_op); return std::transform_reduce(std::forward<Args>(args)...);
#else #else
return std::accumulate(first, last, init, binary_op); return std::inner_product(std::forward<Args>(args)...);
#endif
}
template <class InputIt1, class InputIt2, class T>
T transform_reduce(InputIt1 first1, InputIt1 last1, InputIt2 first2, T init)
{
#if CPP17_PARALLELISM_TS_SUPPORTED
return std::transform_reduce(first1, last1, first2, init);
#else
return std::inner_product(first1, last1, first2, init);
#endif
}
template <class InputIt1, class InputIt2, class T, class BinaryOp1, class BinaryOp2>
T transform_reduce(InputIt1 first1, InputIt1 last1, InputIt2 first2, T init, BinaryOp1 binary_op1, BinaryOp2 binary_op2)
{
#if CPP17_PARALLELISM_TS_SUPPORTED
return std::transform_reduce(first1, last1, first2, init, binary_op1, binary_op2);
#else
return std::inner_product(first1, last1, first2, init, binary_op1, binary_op2);
#endif #endif
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment