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 16namespace std 17{ 18 19template <class InputIterator, class T> 20 constexpr T // constexpr since C++20 21 accumulate(InputIterator first, InputIterator last, T init); 22 23template <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 27template<class InputIterator> 28 constexpr typename iterator_traits<InputIterator>::value_type // constexpr since C++20 29 reduce(InputIterator first, InputIterator last); // C++17 30 31template<class InputIterator, class T> 32 constexpr T // constexpr since C++20 33 reduce(InputIterator first, InputIterator last, T init); // C++17 34 35template<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 39template <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 43template <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 49template<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 54template<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 60template<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 65template <class InputIterator, class OutputIterator> 66 constexpr OutputIterator // constexpr since C++20 67 partial_sum(InputIterator first, InputIterator last, OutputIterator result); 68 69template <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 73template<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 78template<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 83template<class InputIterator, class OutputIterator> 84 constexpr OutputIterator // constexpr since C++20 85 inclusive_scan(InputIterator first, InputIterator last, OutputIterator result); // C++17 86 87template<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 92template<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 97template<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 104template<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 111template<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 119template <class InputIterator, class OutputIterator> 120 constexpr OutputIterator // constexpr since C++20 121 adjacent_difference(InputIterator first, InputIterator last, OutputIterator result); 122 123template <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 127template <class ForwardIterator, class T> 128 constexpr void // constexpr since C++20 129 iota(ForwardIterator first, ForwardIterator last, T value); 130 131template <class M, class N> 132 constexpr common_type_t<M,N> gcd(M m, N n); // C++17 133 134template <class M, class N> 135 constexpr common_type_t<M,N> lcm(M m, N n); // C++17 136 137template<class T> 138 constexpr T midpoint(T a, T b) noexcept; // C++20 139 140template<class T> 141 constexpr T* midpoint(T* a, T* b); // C++20 142 143// [numeric.sat], saturation arithmetic 144template<class T> 145constexpr T add_sat(T x, T y) noexcept; // freestanding, Since C++26 146template<class T> 147constexpr T sub_sat(T x, T y) noexcept; // freestanding, Since C++26 148template<class T> 149constexpr T mul_sat(T x, T y) noexcept; // freestanding, Since C++26 150template<class T> 151constexpr T div_sat(T x, T y) noexcept; // freestanding, Since C++26 152template<class T, class U> 153constexpr T saturate_cast(U x) noexcept; // freestanding, Since C++26 154 155} // std 156 157*/ 158 159#include <__config> 160 161#include <__numeric/accumulate.h> 162#include <__numeric/adjacent_difference.h> 163#include <__numeric/inner_product.h> 164#include <__numeric/iota.h> 165#include <__numeric/partial_sum.h> 166 167#if _LIBCPP_STD_VER >= 17 168# include <__numeric/exclusive_scan.h> 169# include <__numeric/gcd_lcm.h> 170# include <__numeric/inclusive_scan.h> 171# include <__numeric/pstl.h> 172# include <__numeric/reduce.h> 173# include <__numeric/transform_exclusive_scan.h> 174# include <__numeric/transform_inclusive_scan.h> 175# include <__numeric/transform_reduce.h> 176#endif 177 178#if _LIBCPP_STD_VER >= 20 179# include <__numeric/midpoint.h> 180# include <__numeric/saturation_arithmetic.h> 181#endif 182 183#include <version> 184 185#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 186# pragma GCC system_header 187#endif 188 189#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 14 190# include <initializer_list> 191# include <limits> 192#endif 193 194#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 195# include <climits> 196# include <cmath> 197# include <concepts> 198# include <cstdint> 199# include <execution> 200# include <functional> 201# include <iterator> 202# include <new> 203# include <optional> 204# include <type_traits> 205#endif 206 207#endif // _LIBCPP_NUMERIC 208