xref: /freebsd/contrib/llvm-project/libcxx/include/numeric (revision d5b0e70f7e04d971691517ce1304d86a1e367e2e)
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}  // std
144
145*/
146
147#include <__config>
148#include <cmath> // for isnormal
149#include <functional>
150#include <iterator>
151#include <version>
152
153#include <__numeric/accumulate.h>
154#include <__numeric/adjacent_difference.h>
155#include <__numeric/exclusive_scan.h>
156#include <__numeric/gcd_lcm.h>
157#include <__numeric/inclusive_scan.h>
158#include <__numeric/inner_product.h>
159#include <__numeric/iota.h>
160#include <__numeric/midpoint.h>
161#include <__numeric/partial_sum.h>
162#include <__numeric/reduce.h>
163#include <__numeric/transform_exclusive_scan.h>
164#include <__numeric/transform_inclusive_scan.h>
165#include <__numeric/transform_reduce.h>
166
167#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
168#pragma GCC system_header
169#endif
170
171#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
172#   include <__pstl_numeric>
173#endif
174
175#endif // _LIBCPP_NUMERIC
176