Implement inclusive_scan/transform_inclusive_scan for C++17.

llvm-svn: 306083
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: ac8ea7c6ff4d67c874b0f65e0566be5c37568de8
diff --git a/include/numeric b/include/numeric
index 39e8193..1b7d97c 100644
--- a/include/numeric
+++ b/include/numeric
@@ -81,6 +81,20 @@
     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 @@
                              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 @@
     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 @@
     }
     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>