llvm-project/libcxx/include/numeric

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

180 lines
7.4 KiB
Plaintext
Raw Normal View History

2010-05-12 03:42:16 +08:00
// -*- C++ -*-
//===----------------------------------------------------------------------===//
2010-05-12 03:42:16 +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>
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>
constexpr T // constexpr since C++20
2010-05-12 03:42:16 +08:00
accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op);
template<class InputIterator>
constexpr typename iterator_traits<InputIterator>::value_type // constexpr since C++20
reduce(InputIterator first, InputIterator last); // C++17
template<class InputIterator, class T>
constexpr T // constexpr since C++20
reduce(InputIterator first, InputIterator last, T init); // C++17
template<class InputIterator, class T, class BinaryOperation>
constexpr T // constexpr since C++20
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>
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>
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);
template<class InputIterator1, class InputIterator2, class T>
constexpr T // constexpr since C++20
transform_reduce(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init); // C++17
template<class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2>
constexpr T // constexpr since C++20
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>
constexpr T // constexpr since C++20
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>
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>
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);
template<class InputIterator, class OutputIterator, class T>
constexpr OutputIterator // constexpr since C++20
exclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, T init); // C++17
template<class InputIterator, class OutputIterator, class T, class BinaryOperation>
constexpr OutputIterator // constexpr since C++20
exclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, T init, BinaryOperation binary_op); // C++17
template<class InputIterator, class OutputIterator>
constexpr OutputIterator // constexpr since C++20
inclusive_scan(InputIterator first, InputIterator last, OutputIterator result); // C++17
template<class InputIterator, class OutputIterator, class BinaryOperation>
constexpr OutputIterator // constexpr since C++20
inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, BinaryOperation binary_op); // C++17
template<class InputIterator, class OutputIterator, class BinaryOperation, class T>
constexpr OutputIterator // constexpr since C++20
inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, BinaryOperation binary_op, T init); // C++17
template<class InputIterator, class OutputIterator, class T,
class BinaryOperation, class UnaryOperation>
constexpr OutputIterator // constexpr since C++20
transform_exclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, T init,
BinaryOperation binary_op, UnaryOperation unary_op); // C++17
template<class InputIterator, class OutputIterator,
class BinaryOperation, class UnaryOperation>
constexpr OutputIterator // constexpr since C++20
transform_inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result,
BinaryOperation binary_op, UnaryOperation unary_op); // C++17
template<class InputIterator, class OutputIterator,
class BinaryOperation, class UnaryOperation, class T>
constexpr OutputIterator // constexpr since C++20
transform_inclusive_scan(InputIterator first, InputIterator last,
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>
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>
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>
constexpr void // constexpr since C++20
iota(ForwardIterator first, ForwardIterator last, T value);
2010-05-27 02:53:44 +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
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
2010-05-12 03:42:16 +08:00
} // std
*/
#include <__assert> // all public C++ headers provide the assertion handler
2010-05-12 03:42:16 +08:00
#include <__config>
#include <cmath> // for isnormal
#include <version>
2010-05-12 03:42:16 +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>
[libc++] Re-add transitive includes that had been removed since LLVM 14 This commit re-adds transitive includes that had been removed by 4cd04d1687f1, c36870c8e79c, a83f4b9cda57, 1458458b558d, 2e2f3158c604, and 489637e66dd3. This should cover almost all the includes that had been removed since LLVM 14 and that would contribute to breaking user code when releasing LLVM 15. It is possible to disable the inclusion of these headers by defining _LIBCPP_REMOVE_TRANSITIVE_INCLUDES. The intent is that vendors will enable that macro and start fixing downstream issues immediately. We can then remove the macro (and the transitive includes) by default in a future release. That way, we will break users only once by removing transitive includes in bulk instead of doing it bit by bit a every release, which is more disruptive for users. Note 1: The set of headers to re-add was found by re-generating the transitive include test on a checkout of release/14.x, which provided the list of all transitive includes we used to provide. Note 2: Several includes of <vector>, <optional>, <array> and <unordered_map> have been added in this commit. These transitive inclusions were added when we implemented boyer_moore_searcher in <functional>. Note 3: This is a best effort patch to try and resolve downstream breakage caused since branching LLVM 14. I wasn't able to perfectly mirror transitive includes in LLVM 14 for a few headers, so I added a release note explaining it. To summarize, adding boyer_moore_searcher created a bunch of circular dependencies, so we have to break backwards compatibility in a few cases. Differential Revision: https://reviews.llvm.org/D128661
2022-06-28 03:53:41 +08:00
#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
# include <functional>
# include <iterator>
#endif
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
2010-05-12 03:42:16 +08:00
#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
# include <__pstl_numeric>
#endif
#endif // _LIBCPP_NUMERIC