numeric 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. #ifndef _LIBCPP_NUMERIC
  10. #define _LIBCPP_NUMERIC
  11. /*
  12. numeric synopsis
  13. namespace std
  14. {
  15. template <class InputIterator, class T>
  16. constexpr T // constexpr since C++20
  17. accumulate(InputIterator first, InputIterator last, T init);
  18. template <class InputIterator, class T, class BinaryOperation>
  19. constexpr T // constexpr since C++20
  20. accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op);
  21. template<class InputIterator>
  22. constexpr typename iterator_traits<InputIterator>::value_type // constexpr since C++20
  23. reduce(InputIterator first, InputIterator last); // C++17
  24. template<class InputIterator, class T>
  25. constexpr T // constexpr since C++20
  26. reduce(InputIterator first, InputIterator last, T init); // C++17
  27. template<class InputIterator, class T, class BinaryOperation>
  28. constexpr T // constexpr since C++20
  29. reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); // C++17
  30. template <class InputIterator1, class InputIterator2, class T>
  31. constexpr T // constexpr since C++20
  32. inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init);
  33. template <class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2>
  34. constexpr T // constexpr since C++20
  35. inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
  36. T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);
  37. template<class InputIterator1, class InputIterator2, class T>
  38. constexpr T // constexpr since C++20
  39. transform_reduce(InputIterator1 first1, InputIterator1 last1,
  40. InputIterator2 first2, T init); // C++17
  41. template<class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2>
  42. constexpr T // constexpr since C++20
  43. transform_reduce(InputIterator1 first1, InputIterator1 last1,
  44. InputIterator2 first2, T init,
  45. BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); // C++17
  46. template<class InputIterator, class T, class BinaryOperation, class UnaryOperation>
  47. constexpr T // constexpr since C++20
  48. transform_reduce(InputIterator first, InputIterator last, T init,
  49. BinaryOperation binary_op, UnaryOperation unary_op); // C++17
  50. template <class InputIterator, class OutputIterator>
  51. constexpr OutputIterator // constexpr since C++20
  52. partial_sum(InputIterator first, InputIterator last, OutputIterator result);
  53. template <class InputIterator, class OutputIterator, class BinaryOperation>
  54. constexpr OutputIterator // constexpr since C++20
  55. partial_sum(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op);
  56. template<class InputIterator, class OutputIterator, class T>
  57. constexpr OutputIterator // constexpr since C++20
  58. exclusive_scan(InputIterator first, InputIterator last,
  59. OutputIterator result, T init); // C++17
  60. template<class InputIterator, class OutputIterator, class T, class BinaryOperation>
  61. constexpr OutputIterator // constexpr since C++20
  62. exclusive_scan(InputIterator first, InputIterator last,
  63. OutputIterator result, T init, BinaryOperation binary_op); // C++17
  64. template<class InputIterator, class OutputIterator>
  65. constexpr OutputIterator // constexpr since C++20
  66. inclusive_scan(InputIterator first, InputIterator last, OutputIterator result); // C++17
  67. template<class InputIterator, class OutputIterator, class BinaryOperation>
  68. constexpr OutputIterator // constexpr since C++20
  69. inclusive_scan(InputIterator first, InputIterator last,
  70. OutputIterator result, BinaryOperation binary_op); // C++17
  71. template<class InputIterator, class OutputIterator, class BinaryOperation, class T>
  72. constexpr OutputIterator // constexpr since C++20
  73. inclusive_scan(InputIterator first, InputIterator last,
  74. OutputIterator result, BinaryOperation binary_op, T init); // C++17
  75. template<class InputIterator, class OutputIterator, class T,
  76. class BinaryOperation, class UnaryOperation>
  77. constexpr OutputIterator // constexpr since C++20
  78. transform_exclusive_scan(InputIterator first, InputIterator last,
  79. OutputIterator result, T init,
  80. BinaryOperation binary_op, UnaryOperation unary_op); // C++17
  81. template<class InputIterator, class OutputIterator,
  82. class BinaryOperation, class UnaryOperation>
  83. constexpr OutputIterator // constexpr since C++20
  84. transform_inclusive_scan(InputIterator first, InputIterator last,
  85. OutputIterator result,
  86. BinaryOperation binary_op, UnaryOperation unary_op); // C++17
  87. template<class InputIterator, class OutputIterator,
  88. class BinaryOperation, class UnaryOperation, class T>
  89. constexpr OutputIterator // constexpr since C++20
  90. transform_inclusive_scan(InputIterator first, InputIterator last,
  91. OutputIterator result,
  92. BinaryOperation binary_op, UnaryOperation unary_op,
  93. T init); // C++17
  94. template <class InputIterator, class OutputIterator>
  95. constexpr OutputIterator // constexpr since C++20
  96. adjacent_difference(InputIterator first, InputIterator last, OutputIterator result);
  97. template <class InputIterator, class OutputIterator, class BinaryOperation>
  98. constexpr OutputIterator // constexpr since C++20
  99. adjacent_difference(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op);
  100. template <class ForwardIterator, class T>
  101. constexpr void // constexpr since C++20
  102. iota(ForwardIterator first, ForwardIterator last, T value);
  103. template <class M, class N>
  104. constexpr common_type_t<M,N> gcd(M m, N n); // C++17
  105. template <class M, class N>
  106. constexpr common_type_t<M,N> lcm(M m, N n); // C++17
  107. template<class T>
  108. constexpr T midpoint(T a, T b) noexcept; // C++20
  109. template<class T>
  110. constexpr T* midpoint(T* a, T* b); // C++20
  111. } // std
  112. */
  113. #include <__assert> // all public C++ headers provide the assertion handler
  114. #include <__config>
  115. #include <cmath> // for isnormal
  116. #include <version>
  117. #include <__numeric/accumulate.h>
  118. #include <__numeric/adjacent_difference.h>
  119. #include <__numeric/exclusive_scan.h>
  120. #include <__numeric/gcd_lcm.h>
  121. #include <__numeric/inclusive_scan.h>
  122. #include <__numeric/inner_product.h>
  123. #include <__numeric/iota.h>
  124. #include <__numeric/midpoint.h>
  125. #include <__numeric/partial_sum.h>
  126. #include <__numeric/reduce.h>
  127. #include <__numeric/transform_exclusive_scan.h>
  128. #include <__numeric/transform_inclusive_scan.h>
  129. #include <__numeric/transform_reduce.h>
  130. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  131. # pragma GCC system_header
  132. #endif
  133. #if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
  134. #error # include <__pstl_numeric>
  135. #endif
  136. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
  137. # include <concepts>
  138. # include <functional>
  139. # include <iterator>
  140. # include <type_traits>
  141. #endif
  142. #endif // _LIBCPP_NUMERIC