diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2017-06-10 02:22:13 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2017-06-10 02:22:13 +0000 |
commit | e948ba1cd18f64f4a0bd5d534ddd0093d34cf245 (patch) | |
tree | 1977fb7162f1ab09d38eb7482b586554da7bdce8 /libcxx/include/numeric | |
parent | 07c87416447b0703203fc71f6f0680287595b855 (diff) | |
download | bcm5719-llvm-e948ba1cd18f64f4a0bd5d534ddd0093d34cf245.tar.gz bcm5719-llvm-e948ba1cd18f64f4a0bd5d534ddd0093d34cf245.zip |
Implement the non-parallel versions of exclusive_scan and transform_exclusive_scan. Reviewed as https://reviews.llvm.org/D34038.
llvm-svn: 305136
Diffstat (limited to 'libcxx/include/numeric')
-rw-r--r-- | libcxx/include/numeric | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/libcxx/include/numeric b/libcxx/include/numeric index 0e53ba33c3c..a84fb862b66 100644 --- a/libcxx/include/numeric +++ b/libcxx/include/numeric @@ -42,6 +42,23 @@ template <class InputIterator, class OutputIterator, class BinaryOperation> OutputIterator partial_sum(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); +template<class InputIterator, class OutputIterator, class T> + OutputIterator + exclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, T init); // C++17 + +template<class InputIterator, class OutputIterator, class T, class BinaryOperation> + OutputIterator + exclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, T init, BinaryOperation binary_op); // C++17 + +template<class InputIterator, class OutputIterator, class T, + class BinaryOperation, class UnaryOperation> + OutputIterator + transform_exclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, T init, + BinaryOperation binary_op, UnaryOperation unary_op); // C++17 + template <class InputIterator, class OutputIterator> OutputIterator adjacent_difference(InputIterator first, InputIterator last, OutputIterator result); @@ -66,6 +83,7 @@ template <class M, class N> #include <__config> #include <iterator> #include <limits> // for numeric_limits +#include <functional> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header @@ -154,6 +172,59 @@ partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __res return __result; } +#if _LIBCPP_STD_VER > 14 +template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +exclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _Tp __init, _BinaryOp __b) +{ + if (__first != __last) + { + _Tp __saved = __init; + do + { + __init = __b(__init, *__first); + *__result = __saved; + __saved = __init; + ++__result; + } while (++__first != __last); + } + return __result; +} + +template <class _InputIterator, class _OutputIterator, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +exclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _Tp __init) +{ + return _VSTD::exclusive_scan(__first, __last, __result, __init, _VSTD::plus<>()); +} + +template <class _InputIterator, class _OutputIterator, class _Tp, + class _BinaryOp, class _UnaryOp> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +transform_exclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _Tp __init, + _BinaryOp __b, _UnaryOp __u) +{ + if (__first != __last) + { + _Tp __saved = __init; + do + { + __init = __b(__init, __u(*__first)); + *__result = __saved; + __saved = __init; + ++__result; + } while (++__first != __last); + } + return __result; +} +#endif + template <class _InputIterator, class _OutputIterator> inline _LIBCPP_INLINE_VISIBILITY _OutputIterator |