xref: /freebsd-src/contrib/llvm-project/libcxx/include/__numeric/exclusive_scan.h (revision 4824e7fd18a1223177218d4aec1b3c6c5c4a444e)
1*4824e7fdSDimitry Andric // -*- C++ -*-
2*4824e7fdSDimitry Andric //===----------------------------------------------------------------------===//
3*4824e7fdSDimitry Andric //
4*4824e7fdSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*4824e7fdSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
6*4824e7fdSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*4824e7fdSDimitry Andric //
8*4824e7fdSDimitry Andric //===----------------------------------------------------------------------===//
9*4824e7fdSDimitry Andric 
10*4824e7fdSDimitry Andric #ifndef _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H
11*4824e7fdSDimitry Andric #define _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H
12*4824e7fdSDimitry Andric 
13*4824e7fdSDimitry Andric #include <__config>
14*4824e7fdSDimitry Andric #include <__functional/operations.h>
15*4824e7fdSDimitry Andric #include <__utility/move.h>
16*4824e7fdSDimitry Andric 
17*4824e7fdSDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18*4824e7fdSDimitry Andric #  pragma GCC system_header
19*4824e7fdSDimitry Andric #endif
20*4824e7fdSDimitry Andric 
21*4824e7fdSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
22*4824e7fdSDimitry Andric 
23*4824e7fdSDimitry Andric #if _LIBCPP_STD_VER > 14
24*4824e7fdSDimitry Andric 
25*4824e7fdSDimitry Andric template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp>
26*4824e7fdSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
27*4824e7fdSDimitry Andric exclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init, _BinaryOp __b) {
28*4824e7fdSDimitry Andric   if (__first != __last) {
29*4824e7fdSDimitry Andric     _Tp __tmp(__b(__init, *__first));
30*4824e7fdSDimitry Andric     while (true) {
31*4824e7fdSDimitry Andric       *__result = _VSTD::move(__init);
32*4824e7fdSDimitry Andric       ++__result;
33*4824e7fdSDimitry Andric       ++__first;
34*4824e7fdSDimitry Andric       if (__first == __last)
35*4824e7fdSDimitry Andric         break;
36*4824e7fdSDimitry Andric       __init = _VSTD::move(__tmp);
37*4824e7fdSDimitry Andric       __tmp = __b(__init, *__first);
38*4824e7fdSDimitry Andric     }
39*4824e7fdSDimitry Andric   }
40*4824e7fdSDimitry Andric   return __result;
41*4824e7fdSDimitry Andric }
42*4824e7fdSDimitry Andric 
43*4824e7fdSDimitry Andric template <class _InputIterator, class _OutputIterator, class _Tp>
44*4824e7fdSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
45*4824e7fdSDimitry Andric exclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init) {
46*4824e7fdSDimitry Andric   return _VSTD::exclusive_scan(__first, __last, __result, __init, _VSTD::plus<>());
47*4824e7fdSDimitry Andric }
48*4824e7fdSDimitry Andric 
49*4824e7fdSDimitry Andric #endif // _LIBCPP_STD_VER > 14
50*4824e7fdSDimitry Andric 
51*4824e7fdSDimitry Andric _LIBCPP_END_NAMESPACE_STD
52*4824e7fdSDimitry Andric 
53*4824e7fdSDimitry Andric #endif // _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H
54