xref: /freebsd/contrib/llvm-project/libcxx/include/numeric (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric// -*- C++ -*-
2349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_NUMERIC
110b57cec5SDimitry Andric#define _LIBCPP_NUMERIC
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric/*
140b57cec5SDimitry Andric    numeric synopsis
150b57cec5SDimitry Andric
160b57cec5SDimitry Andricnamespace std
170b57cec5SDimitry Andric{
180b57cec5SDimitry Andric
190b57cec5SDimitry Andrictemplate <class InputIterator, class T>
20e8d8bef9SDimitry Andric    constexpr T  // constexpr since C++20
210b57cec5SDimitry Andric    accumulate(InputIterator first, InputIterator last, T init);
220b57cec5SDimitry Andric
230b57cec5SDimitry Andrictemplate <class InputIterator, class T, class BinaryOperation>
24e8d8bef9SDimitry Andric    constexpr T  // constexpr since C++20
250b57cec5SDimitry Andric    accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op);
260b57cec5SDimitry Andric
270b57cec5SDimitry Andrictemplate<class InputIterator>
28e8d8bef9SDimitry Andric    constexpr typename iterator_traits<InputIterator>::value_type  // constexpr since C++20
290b57cec5SDimitry Andric    reduce(InputIterator first, InputIterator last);  // C++17
300b57cec5SDimitry Andric
310b57cec5SDimitry Andrictemplate<class InputIterator, class T>
32e8d8bef9SDimitry Andric    constexpr T  // constexpr since C++20
330b57cec5SDimitry Andric    reduce(InputIterator first, InputIterator last, T init);  // C++17
340b57cec5SDimitry Andric
350b57cec5SDimitry Andrictemplate<class InputIterator, class T, class BinaryOperation>
36e8d8bef9SDimitry Andric    constexpr T  // constexpr since C++20
370b57cec5SDimitry Andric    reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op);  // C++17
380b57cec5SDimitry Andric
390b57cec5SDimitry Andrictemplate <class InputIterator1, class InputIterator2, class T>
40e8d8bef9SDimitry Andric    constexpr T  // constexpr since C++20
410b57cec5SDimitry Andric    inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init);
420b57cec5SDimitry Andric
430b57cec5SDimitry Andrictemplate <class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2>
44e8d8bef9SDimitry Andric    constexpr T  // constexpr since C++20
450b57cec5SDimitry Andric    inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
460b57cec5SDimitry Andric                  T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);
470b57cec5SDimitry Andric
480b57cec5SDimitry Andric
490b57cec5SDimitry Andrictemplate<class InputIterator1, class InputIterator2, class T>
50e8d8bef9SDimitry Andric    constexpr T  // constexpr since C++20
510b57cec5SDimitry Andric    transform_reduce(InputIterator1 first1, InputIterator1 last1,
520b57cec5SDimitry Andric                     InputIterator2 first2, T init);  // C++17
530b57cec5SDimitry Andric
540b57cec5SDimitry Andrictemplate<class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2>
55e8d8bef9SDimitry Andric    constexpr T  // constexpr since C++20
560b57cec5SDimitry Andric    transform_reduce(InputIterator1 first1, InputIterator1 last1,
570b57cec5SDimitry Andric                     InputIterator2 first2, T init,
580b57cec5SDimitry Andric                     BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);  // C++17
590b57cec5SDimitry Andric
600b57cec5SDimitry Andrictemplate<class InputIterator, class T, class BinaryOperation, class UnaryOperation>
61e8d8bef9SDimitry Andric    constexpr T  // constexpr since C++20
620b57cec5SDimitry Andric    transform_reduce(InputIterator first, InputIterator last, T init,
630b57cec5SDimitry Andric                     BinaryOperation binary_op, UnaryOperation unary_op);  // C++17
640b57cec5SDimitry Andric
650b57cec5SDimitry Andrictemplate <class InputIterator, class OutputIterator>
66e8d8bef9SDimitry Andric    constexpr OutputIterator  // constexpr since C++20
670b57cec5SDimitry Andric    partial_sum(InputIterator first, InputIterator last, OutputIterator result);
680b57cec5SDimitry Andric
690b57cec5SDimitry Andrictemplate <class InputIterator, class OutputIterator, class BinaryOperation>
70e8d8bef9SDimitry Andric    constexpr OutputIterator  // constexpr since C++20
710b57cec5SDimitry Andric    partial_sum(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op);
720b57cec5SDimitry Andric
730b57cec5SDimitry Andrictemplate<class InputIterator, class OutputIterator, class T>
74e8d8bef9SDimitry Andric    constexpr OutputIterator  // constexpr since C++20
750b57cec5SDimitry Andric    exclusive_scan(InputIterator first, InputIterator last,
760b57cec5SDimitry Andric                   OutputIterator result, T init); // C++17
770b57cec5SDimitry Andric
780b57cec5SDimitry Andrictemplate<class InputIterator, class OutputIterator, class T, class BinaryOperation>
79e8d8bef9SDimitry Andric    constexpr OutputIterator  // constexpr since C++20
800b57cec5SDimitry Andric    exclusive_scan(InputIterator first, InputIterator last,
810b57cec5SDimitry Andric                   OutputIterator result, T init, BinaryOperation binary_op); // C++17
820b57cec5SDimitry Andric
830b57cec5SDimitry Andrictemplate<class InputIterator, class OutputIterator>
84e8d8bef9SDimitry Andric    constexpr OutputIterator  // constexpr since C++20
850b57cec5SDimitry Andric    inclusive_scan(InputIterator first, InputIterator last, OutputIterator result);  // C++17
860b57cec5SDimitry Andric
870b57cec5SDimitry Andrictemplate<class InputIterator, class OutputIterator, class BinaryOperation>
88e8d8bef9SDimitry Andric    constexpr OutputIterator  // constexpr since C++20
890b57cec5SDimitry Andric    inclusive_scan(InputIterator first, InputIterator last,
900b57cec5SDimitry Andric                   OutputIterator result, BinaryOperation binary_op);  // C++17
910b57cec5SDimitry Andric
920b57cec5SDimitry Andrictemplate<class InputIterator, class OutputIterator, class BinaryOperation, class T>
93e8d8bef9SDimitry Andric    constexpr OutputIterator  // constexpr since C++20
940b57cec5SDimitry Andric    inclusive_scan(InputIterator first, InputIterator last,
950b57cec5SDimitry Andric                   OutputIterator result, BinaryOperation binary_op, T init);  // C++17
960b57cec5SDimitry Andric
970b57cec5SDimitry Andrictemplate<class InputIterator, class OutputIterator, class T,
980b57cec5SDimitry Andric         class BinaryOperation, class UnaryOperation>
99e8d8bef9SDimitry Andric    constexpr OutputIterator  // constexpr since C++20
1000b57cec5SDimitry Andric    transform_exclusive_scan(InputIterator first, InputIterator last,
1010b57cec5SDimitry Andric                             OutputIterator result, T init,
1020b57cec5SDimitry Andric                             BinaryOperation binary_op, UnaryOperation unary_op);  // C++17
1030b57cec5SDimitry Andric
1040b57cec5SDimitry Andrictemplate<class InputIterator, class OutputIterator,
1050b57cec5SDimitry Andric         class BinaryOperation, class UnaryOperation>
106e8d8bef9SDimitry Andric    constexpr OutputIterator  // constexpr since C++20
1070b57cec5SDimitry Andric    transform_inclusive_scan(InputIterator first, InputIterator last,
1080b57cec5SDimitry Andric                             OutputIterator result,
1090b57cec5SDimitry Andric                             BinaryOperation binary_op, UnaryOperation unary_op);  // C++17
1100b57cec5SDimitry Andric
1110b57cec5SDimitry Andrictemplate<class InputIterator, class OutputIterator,
1120b57cec5SDimitry Andric         class BinaryOperation, class UnaryOperation, class T>
113e8d8bef9SDimitry Andric    constexpr OutputIterator  // constexpr since C++20
1140b57cec5SDimitry Andric    transform_inclusive_scan(InputIterator first, InputIterator last,
1150b57cec5SDimitry Andric                             OutputIterator result,
1160b57cec5SDimitry Andric                             BinaryOperation binary_op, UnaryOperation unary_op,
1170b57cec5SDimitry Andric                             T init);  // C++17
1180b57cec5SDimitry Andric
1190b57cec5SDimitry Andrictemplate <class InputIterator, class OutputIterator>
120e8d8bef9SDimitry Andric    constexpr OutputIterator  // constexpr since C++20
1210b57cec5SDimitry Andric    adjacent_difference(InputIterator first, InputIterator last, OutputIterator result);
1220b57cec5SDimitry Andric
1230b57cec5SDimitry Andrictemplate <class InputIterator, class OutputIterator, class BinaryOperation>
124e8d8bef9SDimitry Andric    constexpr OutputIterator  // constexpr since C++20
1250b57cec5SDimitry Andric    adjacent_difference(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op);
1260b57cec5SDimitry Andric
1270b57cec5SDimitry Andrictemplate <class ForwardIterator, class T>
128e8d8bef9SDimitry Andric    constexpr void  // constexpr since C++20
129e8d8bef9SDimitry Andric    iota(ForwardIterator first, ForwardIterator last, T value);
1300b57cec5SDimitry Andric
1310b57cec5SDimitry Andrictemplate <class M, class N>
1320b57cec5SDimitry Andric    constexpr common_type_t<M,N> gcd(M m, N n);    // C++17
1330b57cec5SDimitry Andric
1340b57cec5SDimitry Andrictemplate <class M, class N>
1350b57cec5SDimitry Andric    constexpr common_type_t<M,N> lcm(M m, N n);    // C++17
1360b57cec5SDimitry Andric
137e8d8bef9SDimitry Andrictemplate<class T>
138e8d8bef9SDimitry Andric    constexpr T midpoint(T a, T b) noexcept;  // C++20
139e8d8bef9SDimitry Andric
140e8d8bef9SDimitry Andrictemplate<class T>
141e8d8bef9SDimitry Andric    constexpr T* midpoint(T* a, T* b);        // C++20
1420b57cec5SDimitry Andric
1437a6dacacSDimitry Andric// [numeric.sat], saturation arithmetic
1447a6dacacSDimitry Andrictemplate<class T>
1457a6dacacSDimitry Andricconstexpr T add_sat(T x, T y) noexcept;                     // freestanding, Since C++26
1467a6dacacSDimitry Andrictemplate<class T>
1477a6dacacSDimitry Andricconstexpr T sub_sat(T x, T y) noexcept;                     // freestanding, Since C++26
1487a6dacacSDimitry Andrictemplate<class T>
1497a6dacacSDimitry Andricconstexpr T mul_sat(T x, T y) noexcept;                     // freestanding, Since C++26
1507a6dacacSDimitry Andrictemplate<class T>
1517a6dacacSDimitry Andricconstexpr T div_sat(T x, T y) noexcept;                     // freestanding, Since C++26
1527a6dacacSDimitry Andrictemplate<class T, class U>
1537a6dacacSDimitry Andricconstexpr T saturate_cast(U x) noexcept;                    // freestanding, Since C++26
1547a6dacacSDimitry Andric
1550b57cec5SDimitry Andric}  // std
1560b57cec5SDimitry Andric
1570b57cec5SDimitry Andric*/
1580b57cec5SDimitry Andric
1590b57cec5SDimitry Andric#include <__config>
1600b57cec5SDimitry Andric
1614824e7fdSDimitry Andric#include <__numeric/accumulate.h>
1624824e7fdSDimitry Andric#include <__numeric/adjacent_difference.h>
163*0fca6ea1SDimitry Andric#include <__numeric/inner_product.h>
164*0fca6ea1SDimitry Andric#include <__numeric/iota.h>
165*0fca6ea1SDimitry Andric#include <__numeric/partial_sum.h>
166*0fca6ea1SDimitry Andric
167*0fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 17
1684824e7fdSDimitry Andric#  include <__numeric/exclusive_scan.h>
1694824e7fdSDimitry Andric#  include <__numeric/gcd_lcm.h>
1704824e7fdSDimitry Andric#  include <__numeric/inclusive_scan.h>
171*0fca6ea1SDimitry Andric#  include <__numeric/pstl.h>
1724824e7fdSDimitry Andric#  include <__numeric/reduce.h>
1734824e7fdSDimitry Andric#  include <__numeric/transform_exclusive_scan.h>
1744824e7fdSDimitry Andric#  include <__numeric/transform_inclusive_scan.h>
1754824e7fdSDimitry Andric#  include <__numeric/transform_reduce.h>
176*0fca6ea1SDimitry Andric#endif
177*0fca6ea1SDimitry Andric
178*0fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 20
179*0fca6ea1SDimitry Andric#  include <__numeric/midpoint.h>
180*0fca6ea1SDimitry Andric#  include <__numeric/saturation_arithmetic.h>
181*0fca6ea1SDimitry Andric#endif
182*0fca6ea1SDimitry Andric
183*0fca6ea1SDimitry Andric#include <version>
1844824e7fdSDimitry Andric
1850b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1860b57cec5SDimitry Andric#  pragma GCC system_header
1870b57cec5SDimitry Andric#endif
1880b57cec5SDimitry Andric
189*0fca6ea1SDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 14
190*0fca6ea1SDimitry Andric#  include <initializer_list>
191*0fca6ea1SDimitry Andric#  include <limits>
192*0fca6ea1SDimitry Andric#endif
193*0fca6ea1SDimitry Andric
194bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
195*0fca6ea1SDimitry Andric#  include <climits>
1965f757f3fSDimitry Andric#  include <cmath>
197bdd1243dSDimitry Andric#  include <concepts>
198*0fca6ea1SDimitry Andric#  include <cstdint>
199*0fca6ea1SDimitry Andric#  include <execution>
200bdd1243dSDimitry Andric#  include <functional>
201bdd1243dSDimitry Andric#  include <iterator>
202*0fca6ea1SDimitry Andric#  include <new>
203*0fca6ea1SDimitry Andric#  include <optional>
204bdd1243dSDimitry Andric#  include <type_traits>
205bdd1243dSDimitry Andric#endif
206bdd1243dSDimitry Andric
2070b57cec5SDimitry Andric#endif // _LIBCPP_NUMERIC
208