2010-05-12 03:42:16 +08:00
|
|
|
// -*- C++ -*-
|
2021-11-18 05:25:01 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
2019-01-19 18:56:40 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_NUMERIC
|
|
|
|
#define _LIBCPP_NUMERIC
|
|
|
|
|
|
|
|
/*
|
|
|
|
numeric synopsis
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
|
|
|
|
template <class InputIterator, class T>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr T // constexpr since C++20
|
2010-05-12 03:42:16 +08:00
|
|
|
accumulate(InputIterator first, InputIterator last, T init);
|
|
|
|
|
|
|
|
template <class InputIterator, class T, class BinaryOperation>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr T // constexpr since C++20
|
2010-05-12 03:42:16 +08:00
|
|
|
accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op);
|
|
|
|
|
2017-06-14 12:48:45 +08:00
|
|
|
template<class InputIterator>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr typename iterator_traits<InputIterator>::value_type // constexpr since C++20
|
2017-06-14 12:48:45 +08:00
|
|
|
reduce(InputIterator first, InputIterator last); // C++17
|
|
|
|
|
|
|
|
template<class InputIterator, class T>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr T // constexpr since C++20
|
2017-06-14 12:48:45 +08:00
|
|
|
reduce(InputIterator first, InputIterator last, T init); // C++17
|
|
|
|
|
|
|
|
template<class InputIterator, class T, class BinaryOperation>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr T // constexpr since C++20
|
2017-06-14 12:48:45 +08:00
|
|
|
reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); // C++17
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class InputIterator1, class InputIterator2, class T>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr T // constexpr since C++20
|
2010-05-12 03:42:16 +08:00
|
|
|
inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init);
|
|
|
|
|
|
|
|
template <class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr T // constexpr since C++20
|
2010-05-12 03:42:16 +08:00
|
|
|
inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
|
|
|
|
T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);
|
|
|
|
|
2017-06-14 12:48:45 +08:00
|
|
|
|
|
|
|
template<class InputIterator1, class InputIterator2, class T>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr T // constexpr since C++20
|
2017-06-14 12:48:45 +08:00
|
|
|
transform_reduce(InputIterator1 first1, InputIterator1 last1,
|
|
|
|
InputIterator2 first2, T init); // C++17
|
2018-01-05 09:31:55 +08:00
|
|
|
|
2017-06-14 12:48:45 +08:00
|
|
|
template<class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr T // constexpr since C++20
|
2017-06-14 12:48:45 +08:00
|
|
|
transform_reduce(InputIterator1 first1, InputIterator1 last1,
|
|
|
|
InputIterator2 first2, T init,
|
|
|
|
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); // C++17
|
|
|
|
|
|
|
|
template<class InputIterator, class T, class BinaryOperation, class UnaryOperation>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr T // constexpr since C++20
|
2017-06-14 12:48:45 +08:00
|
|
|
transform_reduce(InputIterator first, InputIterator last, T init,
|
|
|
|
BinaryOperation binary_op, UnaryOperation unary_op); // C++17
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class InputIterator, class OutputIterator>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr OutputIterator // constexpr since C++20
|
2010-05-12 03:42:16 +08:00
|
|
|
partial_sum(InputIterator first, InputIterator last, OutputIterator result);
|
|
|
|
|
|
|
|
template <class InputIterator, class OutputIterator, class BinaryOperation>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr OutputIterator // constexpr since C++20
|
2010-05-12 03:42:16 +08:00
|
|
|
partial_sum(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op);
|
|
|
|
|
2017-06-10 10:22:13 +08:00
|
|
|
template<class InputIterator, class OutputIterator, class T>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr OutputIterator // constexpr since C++20
|
2017-06-10 10:22:13 +08:00
|
|
|
exclusive_scan(InputIterator first, InputIterator last,
|
|
|
|
OutputIterator result, T init); // C++17
|
2018-01-05 09:31:55 +08:00
|
|
|
|
2017-06-10 10:22:13 +08:00
|
|
|
template<class InputIterator, class OutputIterator, class T, class BinaryOperation>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr OutputIterator // constexpr since C++20
|
2018-01-05 09:31:55 +08:00
|
|
|
exclusive_scan(InputIterator first, InputIterator last,
|
2017-06-10 10:22:13 +08:00
|
|
|
OutputIterator result, T init, BinaryOperation binary_op); // C++17
|
|
|
|
|
2017-06-23 13:12:42 +08:00
|
|
|
template<class InputIterator, class OutputIterator>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr OutputIterator // constexpr since C++20
|
2017-06-23 13:12:42 +08:00
|
|
|
inclusive_scan(InputIterator first, InputIterator last, OutputIterator result); // C++17
|
|
|
|
|
|
|
|
template<class InputIterator, class OutputIterator, class BinaryOperation>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr OutputIterator // constexpr since C++20
|
2017-06-23 13:12:42 +08:00
|
|
|
inclusive_scan(InputIterator first, InputIterator last,
|
|
|
|
OutputIterator result, BinaryOperation binary_op); // C++17
|
|
|
|
|
|
|
|
template<class InputIterator, class OutputIterator, class BinaryOperation, class T>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr OutputIterator // constexpr since C++20
|
2017-06-23 13:12:42 +08:00
|
|
|
inclusive_scan(InputIterator first, InputIterator last,
|
|
|
|
OutputIterator result, BinaryOperation binary_op, T init); // C++17
|
|
|
|
|
2017-06-10 10:22:13 +08:00
|
|
|
template<class InputIterator, class OutputIterator, class T,
|
|
|
|
class BinaryOperation, class UnaryOperation>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr OutputIterator // constexpr since C++20
|
2017-06-10 10:22:13 +08:00
|
|
|
transform_exclusive_scan(InputIterator first, InputIterator last,
|
|
|
|
OutputIterator result, T init,
|
|
|
|
BinaryOperation binary_op, UnaryOperation unary_op); // C++17
|
|
|
|
|
2017-06-23 13:12:42 +08:00
|
|
|
template<class InputIterator, class OutputIterator,
|
|
|
|
class BinaryOperation, class UnaryOperation>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr OutputIterator // constexpr since C++20
|
2018-08-04 06:36:53 +08:00
|
|
|
transform_inclusive_scan(InputIterator first, InputIterator last,
|
2017-06-23 13:12:42 +08:00
|
|
|
OutputIterator result,
|
|
|
|
BinaryOperation binary_op, UnaryOperation unary_op); // C++17
|
2018-01-05 09:31:55 +08:00
|
|
|
|
2017-06-23 13:12:42 +08:00
|
|
|
template<class InputIterator, class OutputIterator,
|
|
|
|
class BinaryOperation, class UnaryOperation, class T>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr OutputIterator // constexpr since C++20
|
2018-08-04 06:36:53 +08:00
|
|
|
transform_inclusive_scan(InputIterator first, InputIterator last,
|
2017-06-23 13:12:42 +08:00
|
|
|
OutputIterator result,
|
|
|
|
BinaryOperation binary_op, UnaryOperation unary_op,
|
|
|
|
T init); // C++17
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class InputIterator, class OutputIterator>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr OutputIterator // constexpr since C++20
|
2010-05-12 03:42:16 +08:00
|
|
|
adjacent_difference(InputIterator first, InputIterator last, OutputIterator result);
|
|
|
|
|
|
|
|
template <class InputIterator, class OutputIterator, class BinaryOperation>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr OutputIterator // constexpr since C++20
|
2010-05-12 03:42:16 +08:00
|
|
|
adjacent_difference(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op);
|
|
|
|
|
2010-05-27 02:53:44 +08:00
|
|
|
template <class ForwardIterator, class T>
|
2020-11-28 21:50:53 +08:00
|
|
|
constexpr void // constexpr since C++20
|
|
|
|
iota(ForwardIterator first, ForwardIterator last, T value);
|
2010-05-27 02:53:44 +08:00
|
|
|
|
2016-07-26 22:29:45 +08:00
|
|
|
template <class M, class N>
|
|
|
|
constexpr common_type_t<M,N> gcd(M m, N n); // C++17
|
|
|
|
|
|
|
|
template <class M, class N>
|
|
|
|
constexpr common_type_t<M,N> lcm(M m, N n); // C++17
|
|
|
|
|
2020-11-28 21:50:53 +08:00
|
|
|
template<class T>
|
|
|
|
constexpr T midpoint(T a, T b) noexcept; // C++20
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
constexpr T* midpoint(T* a, T* b); // C++20
|
2019-03-15 00:25:55 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
} // std
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2022-03-26 00:55:36 +08:00
|
|
|
#include <__assert> // all public C++ headers provide the assertion handler
|
2010-05-12 03:42:16 +08:00
|
|
|
#include <__config>
|
2021-05-13 11:04:03 +08:00
|
|
|
#include <cmath> // for isnormal
|
2010-05-12 03:42:16 +08:00
|
|
|
#include <iterator>
|
2018-09-13 03:41:40 +08:00
|
|
|
#include <version>
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2021-12-01 09:36:32 +08:00
|
|
|
#include <__numeric/accumulate.h>
|
|
|
|
#include <__numeric/adjacent_difference.h>
|
|
|
|
#include <__numeric/exclusive_scan.h>
|
|
|
|
#include <__numeric/gcd_lcm.h>
|
|
|
|
#include <__numeric/inclusive_scan.h>
|
|
|
|
#include <__numeric/inner_product.h>
|
|
|
|
#include <__numeric/iota.h>
|
|
|
|
#include <__numeric/midpoint.h>
|
|
|
|
#include <__numeric/partial_sum.h>
|
|
|
|
#include <__numeric/reduce.h>
|
|
|
|
#include <__numeric/transform_exclusive_scan.h>
|
|
|
|
#include <__numeric/transform_inclusive_scan.h>
|
|
|
|
#include <__numeric/transform_reduce.h>
|
|
|
|
|
2011-10-18 04:05:10 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2022-02-02 09:16:40 +08:00
|
|
|
# pragma GCC system_header
|
2011-10-18 04:05:10 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2019-08-06 02:29:14 +08:00
|
|
|
#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
|
2019-08-07 05:11:24 +08:00
|
|
|
# include <__pstl_numeric>
|
2019-08-06 02:29:14 +08:00
|
|
|
#endif
|
|
|
|
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_NUMERIC
|