xref: /freebsd-src/contrib/llvm-project/libcxx/include/__numeric/exclusive_scan.h (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
14824e7fdSDimitry Andric // -*- C++ -*-
24824e7fdSDimitry Andric //===----------------------------------------------------------------------===//
34824e7fdSDimitry Andric //
44824e7fdSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
54824e7fdSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
64824e7fdSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
74824e7fdSDimitry Andric //
84824e7fdSDimitry Andric //===----------------------------------------------------------------------===//
94824e7fdSDimitry Andric 
104824e7fdSDimitry Andric #ifndef _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H
114824e7fdSDimitry Andric #define _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H
124824e7fdSDimitry Andric 
134824e7fdSDimitry Andric #include <__config>
144824e7fdSDimitry Andric #include <__functional/operations.h>
154824e7fdSDimitry Andric #include <__utility/move.h>
164824e7fdSDimitry Andric 
174824e7fdSDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
184824e7fdSDimitry Andric #  pragma GCC system_header
194824e7fdSDimitry Andric #endif
204824e7fdSDimitry Andric 
21*06c3fb27SDimitry Andric _LIBCPP_PUSH_MACROS
22*06c3fb27SDimitry Andric #include <__undef_macros>
23*06c3fb27SDimitry Andric 
244824e7fdSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
254824e7fdSDimitry Andric 
26*06c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 17
274824e7fdSDimitry Andric 
284824e7fdSDimitry Andric template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp>
29bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
304824e7fdSDimitry Andric exclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init, _BinaryOp __b) {
314824e7fdSDimitry Andric   if (__first != __last) {
324824e7fdSDimitry Andric     _Tp __tmp(__b(__init, *__first));
334824e7fdSDimitry Andric     while (true) {
344824e7fdSDimitry Andric       *__result = _VSTD::move(__init);
354824e7fdSDimitry Andric       ++__result;
364824e7fdSDimitry Andric       ++__first;
374824e7fdSDimitry Andric       if (__first == __last)
384824e7fdSDimitry Andric         break;
394824e7fdSDimitry Andric       __init = _VSTD::move(__tmp);
404824e7fdSDimitry Andric       __tmp = __b(__init, *__first);
414824e7fdSDimitry Andric     }
424824e7fdSDimitry Andric   }
434824e7fdSDimitry Andric   return __result;
444824e7fdSDimitry Andric }
454824e7fdSDimitry Andric 
464824e7fdSDimitry Andric template <class _InputIterator, class _OutputIterator, class _Tp>
47bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
484824e7fdSDimitry Andric exclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init) {
494824e7fdSDimitry Andric   return _VSTD::exclusive_scan(__first, __last, __result, __init, _VSTD::plus<>());
504824e7fdSDimitry Andric }
514824e7fdSDimitry Andric 
52*06c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 17
534824e7fdSDimitry Andric 
544824e7fdSDimitry Andric _LIBCPP_END_NAMESPACE_STD
554824e7fdSDimitry Andric 
56*06c3fb27SDimitry Andric _LIBCPP_POP_MACROS
57*06c3fb27SDimitry Andric 
584824e7fdSDimitry Andric #endif // _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H
59