Warning: This file is not a C or C++ file. It does not have highlighting.
1 | // -*- C++ -*- |
---|---|
2 | //===----------------------------------------------------------------------===// |
3 | // |
4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
5 | // See https://llvm.org/LICENSE.txt for license information. |
6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
7 | // |
8 | //===----------------------------------------------------------------------===// |
9 | |
10 | #ifndef _LIBCPP___CXX03___NUMERIC_PARTIAL_SUM_H |
11 | #define _LIBCPP___CXX03___NUMERIC_PARTIAL_SUM_H |
12 | |
13 | #include <__cxx03/__config> |
14 | #include <__cxx03/__iterator/iterator_traits.h> |
15 | #include <__cxx03/__utility/move.h> |
16 | |
17 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
18 | # pragma GCC system_header |
19 | #endif |
20 | |
21 | _LIBCPP_PUSH_MACROS |
22 | #include <__cxx03/__undef_macros> |
23 | |
24 | _LIBCPP_BEGIN_NAMESPACE_STD |
25 | |
26 | template <class _InputIterator, class _OutputIterator> |
27 | _LIBCPP_HIDE_FROM_ABI _OutputIterator |
28 | partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { |
29 | if (__first != __last) { |
30 | typename iterator_traits<_InputIterator>::value_type __t(*__first); |
31 | *__result = __t; |
32 | for (++__first, (void)++__result; __first != __last; ++__first, (void)++__result) { |
33 | __t = __t + *__first; |
34 | *__result = __t; |
35 | } |
36 | } |
37 | return __result; |
38 | } |
39 | |
40 | template <class _InputIterator, class _OutputIterator, class _BinaryOperation> |
41 | _LIBCPP_HIDE_FROM_ABI _OutputIterator |
42 | partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOperation __binary_op) { |
43 | if (__first != __last) { |
44 | typename iterator_traits<_InputIterator>::value_type __t(*__first); |
45 | *__result = __t; |
46 | for (++__first, (void)++__result; __first != __last; ++__first, (void)++__result) { |
47 | __t = __binary_op(__t, *__first); |
48 | *__result = __t; |
49 | } |
50 | } |
51 | return __result; |
52 | } |
53 | |
54 | _LIBCPP_END_NAMESPACE_STD |
55 | |
56 | _LIBCPP_POP_MACROS |
57 | |
58 | #endif // _LIBCPP___CXX03___NUMERIC_PARTIAL_SUM_H |
59 |
Warning: This file is not a C or C++ file. It does not have highlighting.