| 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_NUMERIC |
| 11 | #define _LIBCPP_NUMERIC |
| 12 | |
| 13 | /* |
| 14 | numeric synopsis |
| 15 | |
| 16 | namespace std |
| 17 | { |
| 18 | |
| 19 | template <class InputIterator, class T> |
| 20 | constexpr T // constexpr since C++20 |
| 21 | accumulate(InputIterator first, InputIterator last, T init); |
| 22 | |
| 23 | template <class InputIterator, class T, class BinaryOperation> |
| 24 | constexpr T // constexpr since C++20 |
| 25 | accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); |
| 26 | |
| 27 | template<class InputIterator> |
| 28 | constexpr typename iterator_traits<InputIterator>::value_type // constexpr since C++20 |
| 29 | reduce(InputIterator first, InputIterator last); // C++17 |
| 30 | |
| 31 | template<class InputIterator, class T> |
| 32 | constexpr T // constexpr since C++20 |
| 33 | reduce(InputIterator first, InputIterator last, T init); // C++17 |
| 34 | |
| 35 | template<class InputIterator, class T, class BinaryOperation> |
| 36 | constexpr T // constexpr since C++20 |
| 37 | reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); // C++17 |
| 38 | |
| 39 | template <class InputIterator1, class InputIterator2, class T> |
| 40 | constexpr T // constexpr since C++20 |
| 41 | inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init); |
| 42 | |
| 43 | template <class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2> |
| 44 | constexpr T // constexpr since C++20 |
| 45 | inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, |
| 46 | T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); |
| 47 | |
| 48 | |
| 49 | template<class InputIterator1, class InputIterator2, class T> |
| 50 | constexpr T // constexpr since C++20 |
| 51 | transform_reduce(InputIterator1 first1, InputIterator1 last1, |
| 52 | InputIterator2 first2, T init); // C++17 |
| 53 | |
| 54 | template<class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2> |
| 55 | constexpr T // constexpr since C++20 |
| 56 | transform_reduce(InputIterator1 first1, InputIterator1 last1, |
| 57 | InputIterator2 first2, T init, |
| 58 | BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); // C++17 |
| 59 | |
| 60 | template<class InputIterator, class T, class BinaryOperation, class UnaryOperation> |
| 61 | constexpr T // constexpr since C++20 |
| 62 | transform_reduce(InputIterator first, InputIterator last, T init, |
| 63 | BinaryOperation binary_op, UnaryOperation unary_op); // C++17 |
| 64 | |
| 65 | template <class InputIterator, class OutputIterator> |
| 66 | constexpr OutputIterator // constexpr since C++20 |
| 67 | partial_sum(InputIterator first, InputIterator last, OutputIterator result); |
| 68 | |
| 69 | template <class InputIterator, class OutputIterator, class BinaryOperation> |
| 70 | constexpr OutputIterator // constexpr since C++20 |
| 71 | partial_sum(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); |
| 72 | |
| 73 | template<class InputIterator, class OutputIterator, class T> |
| 74 | constexpr OutputIterator // constexpr since C++20 |
| 75 | exclusive_scan(InputIterator first, InputIterator last, |
| 76 | OutputIterator result, T init); // C++17 |
| 77 | |
| 78 | template<class InputIterator, class OutputIterator, class T, class BinaryOperation> |
| 79 | constexpr OutputIterator // constexpr since C++20 |
| 80 | exclusive_scan(InputIterator first, InputIterator last, |
| 81 | OutputIterator result, T init, BinaryOperation binary_op); // C++17 |
| 82 | |
| 83 | template<class InputIterator, class OutputIterator> |
| 84 | constexpr OutputIterator // constexpr since C++20 |
| 85 | inclusive_scan(InputIterator first, InputIterator last, OutputIterator result); // C++17 |
| 86 | |
| 87 | template<class InputIterator, class OutputIterator, class BinaryOperation> |
| 88 | constexpr OutputIterator // constexpr since C++20 |
| 89 | inclusive_scan(InputIterator first, InputIterator last, |
| 90 | OutputIterator result, BinaryOperation binary_op); // C++17 |
| 91 | |
| 92 | template<class InputIterator, class OutputIterator, class BinaryOperation, class T> |
| 93 | constexpr OutputIterator // constexpr since C++20 |
| 94 | inclusive_scan(InputIterator first, InputIterator last, |
| 95 | OutputIterator result, BinaryOperation binary_op, T init); // C++17 |
| 96 | |
| 97 | template<class InputIterator, class OutputIterator, class T, |
| 98 | class BinaryOperation, class UnaryOperation> |
| 99 | constexpr OutputIterator // constexpr since C++20 |
| 100 | transform_exclusive_scan(InputIterator first, InputIterator last, |
| 101 | OutputIterator result, T init, |
| 102 | BinaryOperation binary_op, UnaryOperation unary_op); // C++17 |
| 103 | |
| 104 | template<class InputIterator, class OutputIterator, |
| 105 | class BinaryOperation, class UnaryOperation> |
| 106 | constexpr OutputIterator // constexpr since C++20 |
| 107 | transform_inclusive_scan(InputIterator first, InputIterator last, |
| 108 | OutputIterator result, |
| 109 | BinaryOperation binary_op, UnaryOperation unary_op); // C++17 |
| 110 | |
| 111 | template<class InputIterator, class OutputIterator, |
| 112 | class BinaryOperation, class UnaryOperation, class T> |
| 113 | constexpr OutputIterator // constexpr since C++20 |
| 114 | transform_inclusive_scan(InputIterator first, InputIterator last, |
| 115 | OutputIterator result, |
| 116 | BinaryOperation binary_op, UnaryOperation unary_op, |
| 117 | T init); // C++17 |
| 118 | |
| 119 | template <class InputIterator, class OutputIterator> |
| 120 | constexpr OutputIterator // constexpr since C++20 |
| 121 | adjacent_difference(InputIterator first, InputIterator last, OutputIterator result); |
| 122 | |
| 123 | template <class InputIterator, class OutputIterator, class BinaryOperation> |
| 124 | constexpr OutputIterator // constexpr since C++20 |
| 125 | adjacent_difference(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); |
| 126 | |
| 127 | template <class ForwardIterator, class T> |
| 128 | constexpr void // constexpr since C++20 |
| 129 | iota(ForwardIterator first, ForwardIterator last, T value); |
| 130 | |
| 131 | template <class M, class N> |
| 132 | constexpr common_type_t<M,N> gcd(M m, N n); // C++17 |
| 133 | |
| 134 | template <class M, class N> |
| 135 | constexpr common_type_t<M,N> lcm(M m, N n); // C++17 |
| 136 | |
| 137 | template<class T> |
| 138 | constexpr T midpoint(T a, T b) noexcept; // C++20 |
| 139 | |
| 140 | template<class T> |
| 141 | constexpr T* midpoint(T* a, T* b); // C++20 |
| 142 | |
| 143 | // [numeric.sat], saturation arithmetic |
| 144 | template<class T> |
| 145 | constexpr T add_sat(T x, T y) noexcept; // freestanding, Since C++26 |
| 146 | template<class T> |
| 147 | constexpr T sub_sat(T x, T y) noexcept; // freestanding, Since C++26 |
| 148 | template<class T> |
| 149 | constexpr T mul_sat(T x, T y) noexcept; // freestanding, Since C++26 |
| 150 | template<class T> |
| 151 | constexpr T div_sat(T x, T y) noexcept; // freestanding, Since C++26 |
| 152 | template<class T, class U> |
| 153 | constexpr T saturate_cast(U x) noexcept; // freestanding, Since C++26 |
| 154 | |
| 155 | } // std |
| 156 | |
| 157 | */ |
| 158 | |
| 159 | #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 160 | # include <__cxx03/numeric> |
| 161 | #else |
| 162 | # include <__config> |
| 163 | |
| 164 | # include <__numeric/accumulate.h> |
| 165 | # include <__numeric/adjacent_difference.h> |
| 166 | # include <__numeric/inner_product.h> |
| 167 | # include <__numeric/iota.h> |
| 168 | # include <__numeric/partial_sum.h> |
| 169 | |
| 170 | # if _LIBCPP_STD_VER >= 17 |
| 171 | # include <__numeric/exclusive_scan.h> |
| 172 | # include <__numeric/gcd_lcm.h> |
| 173 | # include <__numeric/inclusive_scan.h> |
| 174 | # include <__numeric/pstl.h> |
| 175 | # include <__numeric/ranges_iota.h> |
| 176 | # include <__numeric/reduce.h> |
| 177 | # include <__numeric/transform_exclusive_scan.h> |
| 178 | # include <__numeric/transform_inclusive_scan.h> |
| 179 | # include <__numeric/transform_reduce.h> |
| 180 | # endif |
| 181 | |
| 182 | # if _LIBCPP_STD_VER >= 20 |
| 183 | # include <__numeric/midpoint.h> |
| 184 | # include <__numeric/saturation_arithmetic.h> |
| 185 | # endif |
| 186 | |
| 187 | # include <version> |
| 188 | |
| 189 | # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 190 | # pragma GCC system_header |
| 191 | # endif |
| 192 | |
| 193 | # if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 14 |
| 194 | # include <initializer_list> |
| 195 | # include <limits> |
| 196 | # endif |
| 197 | |
| 198 | # if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
| 199 | # include <climits> |
| 200 | # include <cmath> |
| 201 | # include <concepts> |
| 202 | # include <cstdint> |
| 203 | # include <execution> |
| 204 | # include <functional> |
| 205 | # include <iterator> |
| 206 | # include <new> |
| 207 | # include <optional> |
| 208 | # include <type_traits> |
| 209 | # endif |
| 210 | #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 211 | |
| 212 | #endif // _LIBCPP_NUMERIC |
| 213 | |