Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
Louis Dionne | 9bd9388 | 2021-11-17 16:25:01 -0500 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 20 | constexpr T // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | accumulate(InputIterator first, InputIterator last, T init); |
| 22 | |
| 23 | template <class InputIterator, class T, class BinaryOperation> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 24 | constexpr T // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 25 | accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); |
| 26 | |
Marshall Clow | 3b7cad2 | 2017-06-14 04:48:45 +0000 | [diff] [blame] | 27 | template<class InputIterator> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 28 | constexpr typename iterator_traits<InputIterator>::value_type // constexpr since C++20 |
Marshall Clow | 3b7cad2 | 2017-06-14 04:48:45 +0000 | [diff] [blame] | 29 | reduce(InputIterator first, InputIterator last); // C++17 |
| 30 | |
| 31 | template<class InputIterator, class T> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 32 | constexpr T // constexpr since C++20 |
Marshall Clow | 3b7cad2 | 2017-06-14 04:48:45 +0000 | [diff] [blame] | 33 | reduce(InputIterator first, InputIterator last, T init); // C++17 |
| 34 | |
| 35 | template<class InputIterator, class T, class BinaryOperation> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 36 | constexpr T // constexpr since C++20 |
Marshall Clow | 3b7cad2 | 2017-06-14 04:48:45 +0000 | [diff] [blame] | 37 | reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); // C++17 |
| 38 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 39 | template <class InputIterator1, class InputIterator2, class T> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 40 | constexpr T // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 41 | inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init); |
| 42 | |
| 43 | template <class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 44 | constexpr T // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 45 | inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, |
| 46 | T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); |
| 47 | |
Marshall Clow | 3b7cad2 | 2017-06-14 04:48:45 +0000 | [diff] [blame] | 48 | |
| 49 | template<class InputIterator1, class InputIterator2, class T> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 50 | constexpr T // constexpr since C++20 |
Marshall Clow | 3b7cad2 | 2017-06-14 04:48:45 +0000 | [diff] [blame] | 51 | transform_reduce(InputIterator1 first1, InputIterator1 last1, |
| 52 | InputIterator2 first2, T init); // C++17 |
Billy Robert O'Neal III | 876ecf9 | 2018-01-05 01:31:55 +0000 | [diff] [blame] | 53 | |
Marshall Clow | 3b7cad2 | 2017-06-14 04:48:45 +0000 | [diff] [blame] | 54 | template<class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 55 | constexpr T // constexpr since C++20 |
Marshall Clow | 3b7cad2 | 2017-06-14 04:48:45 +0000 | [diff] [blame] | 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> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 61 | constexpr T // constexpr since C++20 |
Marshall Clow | 3b7cad2 | 2017-06-14 04:48:45 +0000 | [diff] [blame] | 62 | transform_reduce(InputIterator first, InputIterator last, T init, |
| 63 | BinaryOperation binary_op, UnaryOperation unary_op); // C++17 |
| 64 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 65 | template <class InputIterator, class OutputIterator> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 66 | constexpr OutputIterator // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 67 | partial_sum(InputIterator first, InputIterator last, OutputIterator result); |
| 68 | |
| 69 | template <class InputIterator, class OutputIterator, class BinaryOperation> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 70 | constexpr OutputIterator // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 71 | partial_sum(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); |
| 72 | |
Marshall Clow | 0ce2499 | 2017-06-10 02:22:13 +0000 | [diff] [blame] | 73 | template<class InputIterator, class OutputIterator, class T> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 74 | constexpr OutputIterator // constexpr since C++20 |
Marshall Clow | 0ce2499 | 2017-06-10 02:22:13 +0000 | [diff] [blame] | 75 | exclusive_scan(InputIterator first, InputIterator last, |
| 76 | OutputIterator result, T init); // C++17 |
Billy Robert O'Neal III | 876ecf9 | 2018-01-05 01:31:55 +0000 | [diff] [blame] | 77 | |
Marshall Clow | 0ce2499 | 2017-06-10 02:22:13 +0000 | [diff] [blame] | 78 | template<class InputIterator, class OutputIterator, class T, class BinaryOperation> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 79 | constexpr OutputIterator // constexpr since C++20 |
Billy Robert O'Neal III | 876ecf9 | 2018-01-05 01:31:55 +0000 | [diff] [blame] | 80 | exclusive_scan(InputIterator first, InputIterator last, |
Marshall Clow | 0ce2499 | 2017-06-10 02:22:13 +0000 | [diff] [blame] | 81 | OutputIterator result, T init, BinaryOperation binary_op); // C++17 |
| 82 | |
Marshall Clow | 4c56144 | 2017-06-23 05:12:42 +0000 | [diff] [blame] | 83 | template<class InputIterator, class OutputIterator> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 84 | constexpr OutputIterator // constexpr since C++20 |
Marshall Clow | 4c56144 | 2017-06-23 05:12:42 +0000 | [diff] [blame] | 85 | inclusive_scan(InputIterator first, InputIterator last, OutputIterator result); // C++17 |
| 86 | |
| 87 | template<class InputIterator, class OutputIterator, class BinaryOperation> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 88 | constexpr OutputIterator // constexpr since C++20 |
Marshall Clow | 4c56144 | 2017-06-23 05:12:42 +0000 | [diff] [blame] | 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> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 93 | constexpr OutputIterator // constexpr since C++20 |
Marshall Clow | 4c56144 | 2017-06-23 05:12:42 +0000 | [diff] [blame] | 94 | inclusive_scan(InputIterator first, InputIterator last, |
| 95 | OutputIterator result, BinaryOperation binary_op, T init); // C++17 |
| 96 | |
Marshall Clow | 0ce2499 | 2017-06-10 02:22:13 +0000 | [diff] [blame] | 97 | template<class InputIterator, class OutputIterator, class T, |
| 98 | class BinaryOperation, class UnaryOperation> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 99 | constexpr OutputIterator // constexpr since C++20 |
Marshall Clow | 0ce2499 | 2017-06-10 02:22:13 +0000 | [diff] [blame] | 100 | transform_exclusive_scan(InputIterator first, InputIterator last, |
| 101 | OutputIterator result, T init, |
| 102 | BinaryOperation binary_op, UnaryOperation unary_op); // C++17 |
| 103 | |
Marshall Clow | 4c56144 | 2017-06-23 05:12:42 +0000 | [diff] [blame] | 104 | template<class InputIterator, class OutputIterator, |
| 105 | class BinaryOperation, class UnaryOperation> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 106 | constexpr OutputIterator // constexpr since C++20 |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 107 | transform_inclusive_scan(InputIterator first, InputIterator last, |
Marshall Clow | 4c56144 | 2017-06-23 05:12:42 +0000 | [diff] [blame] | 108 | OutputIterator result, |
| 109 | BinaryOperation binary_op, UnaryOperation unary_op); // C++17 |
Billy Robert O'Neal III | 876ecf9 | 2018-01-05 01:31:55 +0000 | [diff] [blame] | 110 | |
Marshall Clow | 4c56144 | 2017-06-23 05:12:42 +0000 | [diff] [blame] | 111 | template<class InputIterator, class OutputIterator, |
| 112 | class BinaryOperation, class UnaryOperation, class T> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 113 | constexpr OutputIterator // constexpr since C++20 |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 114 | transform_inclusive_scan(InputIterator first, InputIterator last, |
Marshall Clow | 4c56144 | 2017-06-23 05:12:42 +0000 | [diff] [blame] | 115 | OutputIterator result, |
| 116 | BinaryOperation binary_op, UnaryOperation unary_op, |
| 117 | T init); // C++17 |
| 118 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 119 | template <class InputIterator, class OutputIterator> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 120 | constexpr OutputIterator // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 121 | adjacent_difference(InputIterator first, InputIterator last, OutputIterator result); |
| 122 | |
| 123 | template <class InputIterator, class OutputIterator, class BinaryOperation> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 124 | constexpr OutputIterator // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 125 | adjacent_difference(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); |
| 126 | |
Howard Hinnant | f45797f | 2010-05-26 18:53:44 +0000 | [diff] [blame] | 127 | template <class ForwardIterator, class T> |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 128 | constexpr void // constexpr since C++20 |
| 129 | iota(ForwardIterator first, ForwardIterator last, T value); |
Howard Hinnant | f45797f | 2010-05-26 18:53:44 +0000 | [diff] [blame] | 130 | |
Marshall Clow | b8bfc2c | 2016-07-26 14:29:45 +0000 | [diff] [blame] | 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 | |
Mark de Wever | 17c5af4 | 2020-11-28 14:50:53 +0100 | [diff] [blame] | 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 |
Marshall Clow | a5f2c8a | 2019-03-14 16:25:55 +0000 | [diff] [blame] | 142 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 143 | } // std |
| 144 | |
| 145 | */ |
| 146 | |
Louis Dionne | b4fce35 | 2022-03-25 12:55:36 -0400 | [diff] [blame] | 147 | #include <__assert> // all public C++ headers provide the assertion handler |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 148 | #include <__config> |
Arthur O'Dwyer | 597cac4 | 2021-05-12 23:04:03 -0400 | [diff] [blame] | 149 | #include <cmath> // for isnormal |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 150 | #include <version> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 151 | |
Christopher Di Bella | 0df29b3 | 2021-12-01 01:36:32 +0000 | [diff] [blame] | 152 | #include <__numeric/accumulate.h> |
| 153 | #include <__numeric/adjacent_difference.h> |
| 154 | #include <__numeric/exclusive_scan.h> |
| 155 | #include <__numeric/gcd_lcm.h> |
| 156 | #include <__numeric/inclusive_scan.h> |
| 157 | #include <__numeric/inner_product.h> |
| 158 | #include <__numeric/iota.h> |
| 159 | #include <__numeric/midpoint.h> |
| 160 | #include <__numeric/partial_sum.h> |
| 161 | #include <__numeric/reduce.h> |
| 162 | #include <__numeric/transform_exclusive_scan.h> |
| 163 | #include <__numeric/transform_inclusive_scan.h> |
| 164 | #include <__numeric/transform_reduce.h> |
| 165 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 166 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Arthur O'Dwyer | 6eeaa00 | 2022-02-01 20:16:40 -0500 | [diff] [blame] | 167 | # pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 168 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 169 | |
Louis Dionne | 59d0b3c | 2019-08-05 18:29:14 +0000 | [diff] [blame] | 170 | #if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 |
Louis Dionne | d53d8c0 | 2019-08-06 21:11:24 +0000 | [diff] [blame] | 171 | # include <__pstl_numeric> |
Louis Dionne | 59d0b3c | 2019-08-05 18:29:14 +0000 | [diff] [blame] | 172 | #endif |
| 173 | |
Mark de Wever | ee5fe27 | 2022-09-02 17:53:28 +0200 | [diff] [blame^] | 174 | #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
| 175 | # include <functional> |
| 176 | # include <iterator> |
| 177 | #endif |
| 178 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 179 | #endif // _LIBCPP_NUMERIC |