summaryrefslogtreecommitdiffstats
path: root/libcxx/include/numeric
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2017-06-23 05:12:42 +0000
committerMarshall Clow <mclow.lists@gmail.com>2017-06-23 05:12:42 +0000
commitac8ea7c6ff4d67c874b0f65e0566be5c37568de8 (patch)
tree74deac53dd8cbfc151de4077690aa1781df988d0 /libcxx/include/numeric
parent58173b97209bfc907dd0b47ecfc5ab7c1fe1f036 (diff)
downloadbcm5719-llvm-ac8ea7c6ff4d67c874b0f65e0566be5c37568de8.tar.gz
bcm5719-llvm-ac8ea7c6ff4d67c874b0f65e0566be5c37568de8.zip
Implement inclusive_scan/transform_inclusive_scan for C++17.
llvm-svn: 306083
Diffstat (limited to 'libcxx/include/numeric')
-rw-r--r--libcxx/include/numeric87
1 files changed, 87 insertions, 0 deletions
diff --git a/libcxx/include/numeric b/libcxx/include/numeric
index 39e81934dfa..1b7d97c5be0 100644
--- a/libcxx/include/numeric
+++ b/libcxx/include/numeric
@@ -81,6 +81,20 @@ template<class InputIterator, class OutputIterator, class T, class BinaryOperati
exclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, T init, BinaryOperation binary_op); // C++17
+template<class InputIterator, class OutputIterator>
+ OutputIterator
+ inclusive_scan(InputIterator first, InputIterator last, OutputIterator result); // C++17
+
+template<class InputIterator, class OutputIterator, class BinaryOperation>
+ OutputIterator
+ inclusive_scan(InputIterator first, InputIterator last,
+ OutputIterator result, BinaryOperation binary_op); // C++17
+
+template<class InputIterator, class OutputIterator, class BinaryOperation, class T>
+ OutputIterator
+ inclusive_scan(InputIterator first, InputIterator last,
+ OutputIterator result, BinaryOperation binary_op, T init); // C++17
+
template<class InputIterator, class OutputIterator, class T,
class BinaryOperation, class UnaryOperation>
OutputIterator
@@ -88,6 +102,21 @@ template<class InputIterator, class OutputIterator, class T,
OutputIterator result, T init,
BinaryOperation binary_op, UnaryOperation unary_op); // C++17
+template<class InputIterator, class OutputIterator,
+ class BinaryOperation, class UnaryOperation>
+ OutputIterator
+ transform_inclusive_scan(InputIterator first, InputIterator last,
+ OutputIterator result,
+ BinaryOperation binary_op, UnaryOperation unary_op); // C++17
+
+template<class InputIterator, class OutputIterator,
+ class BinaryOperation, class UnaryOperation, class T>
+ OutputIterator
+ transform_inclusive_scan(InputIterator first, InputIterator last,
+ OutputIterator result,
+ BinaryOperation binary_op, UnaryOperation unary_op,
+ T init); // C++17
+
template <class InputIterator, class OutputIterator>
OutputIterator
adjacent_difference(InputIterator first, InputIterator last, OutputIterator result);
@@ -295,6 +324,38 @@ exclusive_scan(_InputIterator __first, _InputIterator __last,
return _VSTD::exclusive_scan(__first, __last, __result, __init, _VSTD::plus<>());
}
+template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp>
+_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last,
+ _OutputIterator __result, _BinaryOp __b, _Tp __init)
+{
+ for (; __first != __last; ++__first, (void) ++__result) {
+ __init = __b(__init, *__first);
+ *__result = __init;
+ }
+ return __result;
+}
+
+template <class _InputIterator, class _OutputIterator, class _BinaryOp>
+_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last,
+ _OutputIterator __result, _BinaryOp __b)
+{
+ if (__first != __last) {
+ typename std::iterator_traits<_InputIterator>::value_type __init = *__first;
+ *__result++ = __init;
+ if (++__first != __last)
+ return _VSTD::inclusive_scan(__first, __last, __result, __b, __init);
+ }
+
+ return __result;
+}
+
+template <class _InputIterator, class _OutputIterator>
+_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last,
+ _OutputIterator __result)
+{
+ return _VSTD::inclusive_scan(__first, __last, __result, std::plus<>());
+}
+
template <class _InputIterator, class _OutputIterator, class _Tp,
class _BinaryOp, class _UnaryOp>
inline _LIBCPP_INLINE_VISIBILITY
@@ -316,6 +377,32 @@ transform_exclusive_scan(_InputIterator __first, _InputIterator __last,
}
return __result;
}
+
+template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp, class _UnaryOp>
+_OutputIterator transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
+ _OutputIterator __result, _BinaryOp __b, _UnaryOp __u, _Tp __init)
+{
+ for (; __first != __last; ++__first, (void) ++__result) {
+ __init = __b(__init, __u(*__first));
+ *__result = __init;
+ }
+
+ return __result;
+}
+
+template <class _InputIterator, class _OutputIterator, class _BinaryOp, class _UnaryOp>
+_OutputIterator transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
+ _OutputIterator __result, _BinaryOp __b, _UnaryOp __u)
+{
+ if (__first != __last) {
+ typename std::iterator_traits<_InputIterator>::value_type __init = __u(*__first);
+ *__result++ = __init;
+ if (++__first != __last)
+ return _VSTD::transform_inclusive_scan(__first, __last, __result, __b, __u, __init);
+ }
+
+ return __result;
+}
#endif
template <class _InputIterator, class _OutputIterator>
OpenPOWER on IntegriCloud