Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:36

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___CXX03___NUMERIC_PARTIAL_SUM_H
0011 #define _LIBCPP___CXX03___NUMERIC_PARTIAL_SUM_H
0012 
0013 #include <__cxx03/__config>
0014 #include <__cxx03/__iterator/iterator_traits.h>
0015 #include <__cxx03/__utility/move.h>
0016 
0017 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0018 #  pragma GCC system_header
0019 #endif
0020 
0021 _LIBCPP_PUSH_MACROS
0022 #include <__cxx03/__undef_macros>
0023 
0024 _LIBCPP_BEGIN_NAMESPACE_STD
0025 
0026 template <class _InputIterator, class _OutputIterator>
0027 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
0028 partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
0029   if (__first != __last) {
0030     typename iterator_traits<_InputIterator>::value_type __t(*__first);
0031     *__result = __t;
0032     for (++__first, (void)++__result; __first != __last; ++__first, (void)++__result) {
0033 #if _LIBCPP_STD_VER >= 20
0034       __t = std::move(__t) + *__first;
0035 #else
0036       __t = __t + *__first;
0037 #endif
0038       *__result = __t;
0039     }
0040   }
0041   return __result;
0042 }
0043 
0044 template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
0045 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
0046 partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOperation __binary_op) {
0047   if (__first != __last) {
0048     typename iterator_traits<_InputIterator>::value_type __t(*__first);
0049     *__result = __t;
0050     for (++__first, (void)++__result; __first != __last; ++__first, (void)++__result) {
0051 #if _LIBCPP_STD_VER >= 20
0052       __t = __binary_op(std::move(__t), *__first);
0053 #else
0054       __t = __binary_op(__t, *__first);
0055 #endif
0056       *__result = __t;
0057     }
0058   }
0059   return __result;
0060 }
0061 
0062 _LIBCPP_END_NAMESPACE_STD
0063 
0064 _LIBCPP_POP_MACROS
0065 
0066 #endif // _LIBCPP___CXX03___NUMERIC_PARTIAL_SUM_H