mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-23 18:38:30 +08:00
Implement the non-parallel versions of reduce and transform_reduce for C++17
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@305365 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -25,6 +25,18 @@ template <class InputIterator, class T, class BinaryOperation>
|
||||
T
|
||||
accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op);
|
||||
|
||||
template<class InputIterator>
|
||||
typename iterator_traits<InputIterator>::value_type
|
||||
reduce(InputIterator first, InputIterator last); // C++17
|
||||
|
||||
template<class InputIterator, class T>
|
||||
T
|
||||
reduce(InputIterator first, InputIterator last, T init); // C++17
|
||||
|
||||
template<class InputIterator, class T, class BinaryOperation>
|
||||
T
|
||||
reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); // C++17
|
||||
|
||||
template <class InputIterator1, class InputIterator2, class T>
|
||||
T
|
||||
inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init);
|
||||
@@ -34,6 +46,23 @@ template <class InputIterator1, class InputIterator2, class T, class BinaryOpera
|
||||
inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
|
||||
T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);
|
||||
|
||||
|
||||
template<class InputIterator1, class InputIterator2, class T>
|
||||
T
|
||||
transform_reduce(InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, T init); // C++17
|
||||
|
||||
template<class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2>
|
||||
T
|
||||
transform_reduce(InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, T init,
|
||||
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); // C++17
|
||||
|
||||
template<class InputIterator, class T, class BinaryOperation, class UnaryOperation>
|
||||
T
|
||||
transform_reduce(InputIterator first, InputIterator last, T init,
|
||||
BinaryOperation binary_op, UnaryOperation unary_op); // C++17
|
||||
|
||||
template <class InputIterator, class OutputIterator>
|
||||
OutputIterator
|
||||
partial_sum(InputIterator first, InputIterator last, OutputIterator result);
|
||||
@@ -114,6 +143,35 @@ accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOpe
|
||||
return __init;
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER > 14
|
||||
template <class _InputIterator, class _Tp, class _BinaryOp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
_Tp
|
||||
reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b)
|
||||
{
|
||||
for (; __first != __last; ++__first)
|
||||
__init = __b(__init, *__first);
|
||||
return __init;
|
||||
}
|
||||
|
||||
template <class _InputIterator, class _Tp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
_Tp
|
||||
reduce(_InputIterator __first, _InputIterator __last, _Tp __init)
|
||||
{
|
||||
return _VSTD::reduce(__first, __last, __init, _VSTD::plus<>());
|
||||
}
|
||||
|
||||
template <class _InputIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
typename iterator_traits<_InputIterator>::value_type
|
||||
reduce(_InputIterator __first, _InputIterator __last)
|
||||
{
|
||||
return _VSTD::reduce(__first, __last,
|
||||
typename iterator_traits<_InputIterator>::value_type{});
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2, class _Tp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
_Tp
|
||||
@@ -135,6 +193,41 @@ inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2
|
||||
return __init;
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER > 14
|
||||
template <class _InputIterator, class _Tp, class _BinaryOp, class _UnaryOp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
_Tp
|
||||
transform_reduce(_InputIterator __first, _InputIterator __last,
|
||||
_Tp __init, _BinaryOp __b, _UnaryOp __u)
|
||||
{
|
||||
for (; __first != __last; ++__first)
|
||||
__init = __b(__init, __u(*__first));
|
||||
return __init;
|
||||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2,
|
||||
class _Tp, class _BinaryOp1, class _BinaryOp2>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
_Tp
|
||||
transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
|
||||
_InputIterator2 __first2, _Tp __init, _BinaryOp1 __b1, _BinaryOp2 __b2)
|
||||
{
|
||||
for (; __first1 != __last1; ++__first1, (void) ++__first2)
|
||||
__init = __b1(__init, __b2(*__first1, *__first2));
|
||||
return __init;
|
||||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2, class _Tp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
_Tp
|
||||
transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
|
||||
_InputIterator2 __first2, _Tp __init)
|
||||
{
|
||||
return _VSTD::transform_reduce(__first1, __last1, __first2, __init,
|
||||
_VSTD::plus<>(), _VSTD::multiplies<>());
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class _InputIterator, class _OutputIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
_OutputIterator
|
||||
|
Reference in New Issue
Block a user