libstdc++
numeric
Go to the documentation of this file.
1 // <numeric> -*- C++ -*-
2 
3 // Copyright (C) 2001-2020 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24 
25 /*
26  *
27  * Copyright (c) 1994
28  * Hewlett-Packard Company
29  *
30  * Permission to use, copy, modify, distribute and sell this software
31  * and its documentation for any purpose is hereby granted without fee,
32  * provided that the above copyright notice appear in all copies and
33  * that both that copyright notice and this permission notice appear
34  * in supporting documentation. Hewlett-Packard Company makes no
35  * representations about the suitability of this software for any
36  * purpose. It is provided "as is" without express or implied warranty.
37  *
38  *
39  * Copyright (c) 1996,1997
40  * Silicon Graphics Computer Systems, Inc.
41  *
42  * Permission to use, copy, modify, distribute and sell this software
43  * and its documentation for any purpose is hereby granted without fee,
44  * provided that the above copyright notice appear in all copies and
45  * that both that copyright notice and this permission notice appear
46  * in supporting documentation. Silicon Graphics makes no
47  * representations about the suitability of this software for any
48  * purpose. It is provided "as is" without express or implied warranty.
49  */
50 
51 /** @file include/numeric
52  * This is a Standard C++ Library header.
53  */
54 
55 #ifndef _GLIBCXX_NUMERIC
56 #define _GLIBCXX_NUMERIC 1
57 
58 #pragma GCC system_header
59 
60 #include <bits/c++config.h>
62 #include <bits/stl_numeric.h>
63 
64 #ifdef _GLIBCXX_PARALLEL
65 # include <parallel/numeric>
66 #endif
67 
68 /**
69  * @defgroup numerics Numerics
70  *
71  * Components for performing numeric operations. Includes support for
72  * complex number types, random number generation, numeric (n-at-a-time)
73  * arrays, generalized numeric algorithms, and mathematical special functions.
74  */
75 
76 #if __cplusplus >= 201402L
77 #include <type_traits>
78 
79 namespace std _GLIBCXX_VISIBILITY(default)
80 {
81 _GLIBCXX_BEGIN_NAMESPACE_VERSION
82 
83 namespace __detail
84 {
85  // std::abs is not constexpr and doesn't support unsigned integers.
86  template<typename _Tp>
87  constexpr
88  enable_if_t<__and_<is_integral<_Tp>, is_signed<_Tp>>::value, _Tp>
89  __abs_integral(_Tp __val)
90  { return __val < 0 ? -__val : __val; }
91 
92  template<typename _Tp>
93  constexpr
94  enable_if_t<__and_<is_integral<_Tp>, is_unsigned<_Tp>>::value, _Tp>
95  __abs_integral(_Tp __val)
96  { return __val; }
97 
98  void __abs_integral(bool) = delete;
99 
100  template<typename _Mn, typename _Nn>
101  constexpr common_type_t<_Mn, _Nn>
102  __gcd(_Mn __m, _Nn __n)
103  {
104  return __m == 0 ? __detail::__abs_integral(__n)
105  : __n == 0 ? __detail::__abs_integral(__m)
106  : __detail::__gcd(__n, __m % __n);
107  }
108 
109  /// Least common multiple
110  template<typename _Mn, typename _Nn>
111  constexpr common_type_t<_Mn, _Nn>
112  __lcm(_Mn __m, _Nn __n)
113  {
114  return (__m != 0 && __n != 0)
115  ? (__detail::__abs_integral(__m) / __detail::__gcd(__m, __n))
116  * __detail::__abs_integral(__n)
117  : 0;
118  }
119 } // namespace __detail
120 
121 #if __cplusplus >= 201703L
122 
123 #define __cpp_lib_gcd_lcm 201606
124 // These were used in drafts of SD-6:
125 #define __cpp_lib_gcd 201606
126 #define __cpp_lib_lcm 201606
127 
128  /// Greatest common divisor
129  template<typename _Mn, typename _Nn>
130  constexpr common_type_t<_Mn, _Nn>
131  gcd(_Mn __m, _Nn __n)
132  {
133  static_assert(is_integral_v<_Mn>, "gcd arguments are integers");
134  static_assert(is_integral_v<_Nn>, "gcd arguments are integers");
135  static_assert(!is_same_v<remove_cv_t<_Mn>, bool>,
136  "gcd arguments are not bools");
137  static_assert(!is_same_v<remove_cv_t<_Nn>, bool>,
138  "gcd arguments are not bools");
139  return __detail::__gcd(__m, __n);
140  }
141 
142  /// Least common multiple
143  template<typename _Mn, typename _Nn>
144  constexpr common_type_t<_Mn, _Nn>
145  lcm(_Mn __m, _Nn __n)
146  {
147  static_assert(is_integral_v<_Mn>, "lcm arguments are integers");
148  static_assert(is_integral_v<_Nn>, "lcm arguments are integers");
149  static_assert(!is_same_v<remove_cv_t<_Mn>, bool>,
150  "lcm arguments are not bools");
151  static_assert(!is_same_v<remove_cv_t<_Nn>, bool>,
152  "lcm arguments are not bools");
153  return __detail::__lcm(__m, __n);
154  }
155 
156 #endif // C++17
157 
158 _GLIBCXX_END_NAMESPACE_VERSION
159 } // namespace std
160 
161 #endif // C++14
162 
163 #if __cplusplus > 201703L
164 #include <limits>
165 
166 namespace std _GLIBCXX_VISIBILITY(default)
167 {
168 _GLIBCXX_BEGIN_NAMESPACE_VERSION
169  // midpoint
170 # define __cpp_lib_interpolate 201902L
171 
172  template<typename _Tp>
173  constexpr
174  enable_if_t<__and_v<is_arithmetic<_Tp>, is_same<remove_cv_t<_Tp>, _Tp>,
175  __not_<is_same<_Tp, bool>>>,
176  _Tp>
177  midpoint(_Tp __a, _Tp __b) noexcept
178  {
179  if constexpr (is_integral_v<_Tp>)
180  {
181  using _Up = make_unsigned_t<_Tp>;
182 
183  int __k = 1;
184  _Up __m = __a;
185  _Up __M = __b;
186  if (__a > __b)
187  {
188  __k = -1;
189  __m = __b;
190  __M = __a;
191  }
192  return __a + __k * _Tp(_Up(__M - __m) / 2);
193  }
194  else // is_floating
195  {
196  constexpr _Tp __lo = numeric_limits<_Tp>::min() * 2;
197  constexpr _Tp __hi = numeric_limits<_Tp>::max() / 2;
198  const _Tp __abs_a = __a < 0 ? -__a : __a;
199  const _Tp __abs_b = __b < 0 ? -__b : __b;
200  if (__abs_a <= __hi && __abs_b <= __hi) [[likely]]
201  return (__a + __b) / 2; // always correctly rounded
202  if (__abs_a < __lo) // not safe to halve __a
203  return __a + __b/2;
204  if (__abs_b < __lo) // not safe to halve __b
205  return __a/2 + __b;
206  return __a/2 + __b/2; // otherwise correctly rounded
207  }
208  }
209 
210  template<typename _Tp>
211  constexpr
212  enable_if_t<__and_v<is_object<_Tp>, bool_constant<sizeof(_Tp) != 0>>, _Tp*>
213  midpoint(_Tp* __a, _Tp* __b) noexcept
214  {
215  return __a + (__b - __a) / 2;
216  }
217 _GLIBCXX_END_NAMESPACE_VERSION
218 } // namespace std
219 
220 #endif // C++20
221 
222 #if __cplusplus > 201402L
223 #include <bits/stl_function.h>
224 
225 namespace std _GLIBCXX_VISIBILITY(default)
226 {
227 _GLIBCXX_BEGIN_NAMESPACE_VERSION
228 
229  /// @addtogroup numeric_ops
230  /// @{
231 
232  /**
233  * @brief Calculate reduction of values in a range.
234  *
235  * @param __first Start of range.
236  * @param __last End of range.
237  * @param __init Starting value to add other values to.
238  * @param __binary_op A binary function object.
239  * @return The final sum.
240  *
241  * Reduce the values in the range `[first,last)` using a binary operation.
242  * The initial value is `init`. The values are not necessarily processed
243  * in order.
244  *
245  * This algorithm is similar to `std::accumulate` but is not required to
246  * perform the operations in order from first to last. For operations
247  * that are commutative and associative the result will be the same as
248  * for `std::accumulate`, but for other operations (such as floating point
249  * arithmetic) the result can be different.
250  */
251  template<typename _InputIterator, typename _Tp, typename _BinaryOperation>
252  _Tp
253  reduce(_InputIterator __first, _InputIterator __last, _Tp __init,
254  _BinaryOperation __binary_op)
255  {
256  using value_type = typename iterator_traits<_InputIterator>::value_type;
257  static_assert(is_invocable_r_v<_Tp, _BinaryOperation&, _Tp&, _Tp&>);
258  static_assert(is_convertible_v<value_type, _Tp>);
259  if constexpr (__is_random_access_iter<_InputIterator>::value)
260  {
261  while ((__last - __first) >= 4)
262  {
263  _Tp __v1 = __binary_op(__first[0], __first[1]);
264  _Tp __v2 = __binary_op(__first[2], __first[3]);
265  _Tp __v3 = __binary_op(__v1, __v2);
266  __init = __binary_op(__init, __v3);
267  __first += 4;
268  }
269  }
270  for (; __first != __last; ++__first)
271  __init = __binary_op(__init, *__first);
272  return __init;
273  }
274 
275  /**
276  * @brief Calculate reduction of values in a range.
277  *
278  * @param __first Start of range.
279  * @param __last End of range.
280  * @param __init Starting value to add other values to.
281  * @return The final sum.
282  *
283  * Reduce the values in the range `[first,last)` using addition.
284  * Equivalent to calling `std::reduce(first, last, init, std::plus<>())`.
285  */
286  template<typename _InputIterator, typename _Tp>
287  inline _Tp
288  reduce(_InputIterator __first, _InputIterator __last, _Tp __init)
289  { return std::reduce(__first, __last, std::move(__init), plus<>()); }
290 
291  /**
292  * @brief Calculate reduction of values in a range.
293  *
294  * @param __first Start of range.
295  * @param __last End of range.
296  * @return The final sum.
297  *
298  * Reduce the values in the range `[first,last)` using addition, with
299  * an initial value of `T{}`, where `T` is the iterator's value type.
300  * Equivalent to calling `std::reduce(first, last, T{}, std::plus<>())`.
301  */
302  template<typename _InputIterator>
303  inline typename iterator_traits<_InputIterator>::value_type
304  reduce(_InputIterator __first, _InputIterator __last)
305  {
306  using value_type = typename iterator_traits<_InputIterator>::value_type;
307  return std::reduce(__first, __last, value_type{}, plus<>());
308  }
309 
310  /**
311  * @brief Combine elements from two ranges and reduce
312  *
313  * @param __first1 Start of first range.
314  * @param __last1 End of first range.
315  * @param __first2 Start of second range.
316  * @param __init Starting value to add other values to.
317  * @param __binary_op1 The function used to perform reduction.
318  * @param __binary_op2 The function used to combine values from the ranges.
319  * @return The final sum.
320  *
321  * Call `binary_op2(first1[n],first2[n])` for each `n` in `[0,last1-first1)`
322  * and then use `binary_op1` to reduce the values returned by `binary_op2`
323  * to a single value of type `T`.
324  *
325  * The range beginning at `first2` must contain at least `last1-first1`
326  * elements.
327  */
328  template<typename _InputIterator1, typename _InputIterator2, typename _Tp,
329  typename _BinaryOperation1, typename _BinaryOperation2>
330  _Tp
331  transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
332  _InputIterator2 __first2, _Tp __init,
333  _BinaryOperation1 __binary_op1,
334  _BinaryOperation2 __binary_op2)
335  {
336  if constexpr (__and_v<__is_random_access_iter<_InputIterator1>,
337  __is_random_access_iter<_InputIterator2>>)
338  {
339  while ((__last1 - __first1) >= 4)
340  {
341  _Tp __v1 = __binary_op1(__binary_op2(__first1[0], __first2[0]),
342  __binary_op2(__first1[1], __first2[1]));
343  _Tp __v2 = __binary_op1(__binary_op2(__first1[2], __first2[2]),
344  __binary_op2(__first1[3], __first2[3]));
345  _Tp __v3 = __binary_op1(__v1, __v2);
346  __init = __binary_op1(__init, __v3);
347  __first1 += 4;
348  __first2 += 4;
349  }
350  }
351  for (; __first1 != __last1; ++__first1, (void) ++__first2)
352  __init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
353  return __init;
354  }
355 
356  /**
357  * @brief Combine elements from two ranges and reduce
358  *
359  * @param __first1 Start of first range.
360  * @param __last1 End of first range.
361  * @param __first2 Start of second range.
362  * @param __init Starting value to add other values to.
363  * @return The final sum.
364  *
365  * Call `first1[n]*first2[n]` for each `n` in `[0,last1-first1)` and then
366  * use addition to sum those products to a single value of type `T`.
367  *
368  * The range beginning at `first2` must contain at least `last1-first1`
369  * elements.
370  */
371  template<typename _InputIterator1, typename _InputIterator2, typename _Tp>
372  inline _Tp
373  transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
374  _InputIterator2 __first2, _Tp __init)
375  {
376  return std::transform_reduce(__first1, __last1, __first2,
377  std::move(__init),
378  plus<>(), multiplies<>());
379  }
380 
381  /**
382  * @brief Transform the elements of a range and reduce
383  *
384  * @param __first Start of range.
385  * @param __last End of range.
386  * @param __init Starting value to add other values to.
387  * @param __binary_op The function used to perform reduction.
388  * @param __unary_op The function used to transform values from the range.
389  * @return The final sum.
390  *
391  * Call `unary_op(first[n])` for each `n` in `[0,last-first)` and then
392  * use `binary_op` to reduce the values returned by `unary_op`
393  * to a single value of type `T`.
394  */
395  template<typename _InputIterator, typename _Tp,
396  typename _BinaryOperation, typename _UnaryOperation>
397  _Tp
398  transform_reduce(_InputIterator __first, _InputIterator __last, _Tp __init,
399  _BinaryOperation __binary_op, _UnaryOperation __unary_op)
400  {
401  if constexpr (__is_random_access_iter<_InputIterator>::value)
402  {
403  while ((__last - __first) >= 4)
404  {
405  _Tp __v1 = __binary_op(__unary_op(__first[0]),
406  __unary_op(__first[1]));
407  _Tp __v2 = __binary_op(__unary_op(__first[2]),
408  __unary_op(__first[3]));
409  _Tp __v3 = __binary_op(__v1, __v2);
410  __init = __binary_op(__init, __v3);
411  __first += 4;
412  }
413  }
414  for (; __first != __last; ++__first)
415  __init = __binary_op(__init, __unary_op(*__first));
416  return __init;
417  }
418 
419  /** @brief Output the cumulative sum of one range to a second range
420  *
421  * @param __first Start of input range.
422  * @param __last End of input range.
423  * @param __result Start of output range.
424  * @param __init Initial value.
425  * @param __binary_op Function to perform summation.
426  * @return The end of the output range.
427  *
428  * Write the cumulative sum (aka prefix sum, aka scan) of the input range
429  * to the output range. Each element of the output range contains the
430  * running total of all earlier elements (and the initial value),
431  * using `binary_op` for summation.
432  *
433  * This function generates an "exclusive" scan, meaning the Nth element
434  * of the output range is the sum of the first N-1 input elements,
435  * so the Nth input element is not included.
436  */
437  template<typename _InputIterator, typename _OutputIterator, typename _Tp,
438  typename _BinaryOperation>
439  _OutputIterator
440  exclusive_scan(_InputIterator __first, _InputIterator __last,
441  _OutputIterator __result, _Tp __init,
442  _BinaryOperation __binary_op)
443  {
444  while (__first != __last)
445  {
446  auto __v = __init;
447  __init = __binary_op(__init, *__first);
448  ++__first;
449  *__result++ = std::move(__v);
450  }
451  return __result;
452  }
453 
454  /** @brief Output the cumulative sum of one range to a second range
455  *
456  * @param __first Start of input range.
457  * @param __last End of input range.
458  * @param __result Start of output range.
459  * @param __init Initial value.
460  * @return The end of the output range.
461  *
462  * Write the cumulative sum (aka prefix sum, aka scan) of the input range
463  * to the output range. Each element of the output range contains the
464  * running total of all earlier elements (and the initial value),
465  * using `std::plus<>` for summation.
466  *
467  * This function generates an "exclusive" scan, meaning the Nth element
468  * of the output range is the sum of the first N-1 input elements,
469  * so the Nth input element is not included.
470  */
471  template<typename _InputIterator, typename _OutputIterator, typename _Tp>
472  inline _OutputIterator
473  exclusive_scan(_InputIterator __first, _InputIterator __last,
474  _OutputIterator __result, _Tp __init)
475  {
476  return std::exclusive_scan(__first, __last, __result, std::move(__init),
477  plus<>());
478  }
479 
480  /** @brief Output the cumulative sum of one range to a second range
481  *
482  * @param __first Start of input range.
483  * @param __last End of input range.
484  * @param __result Start of output range.
485  * @param __binary_op Function to perform summation.
486  * @param __init Initial value.
487  * @return The end of the output range.
488  *
489  * Write the cumulative sum (aka prefix sum, aka scan) of the input range
490  * to the output range. Each element of the output range contains the
491  * running total of all earlier elements (and the initial value),
492  * using `binary_op` for summation.
493  *
494  * This function generates an "inclusive" scan, meaning the Nth element
495  * of the output range is the sum of the first N input elements,
496  * so the Nth input element is included.
497  */
498  template<typename _InputIterator, typename _OutputIterator,
499  typename _BinaryOperation, typename _Tp>
500  _OutputIterator
501  inclusive_scan(_InputIterator __first, _InputIterator __last,
502  _OutputIterator __result, _BinaryOperation __binary_op,
503  _Tp __init)
504  {
505  for (; __first != __last; ++__first)
506  *__result++ = __init = __binary_op(__init, *__first);
507  return __result;
508  }
509 
510  /** @brief Output the cumulative sum of one range to a second range
511  *
512  * @param __first Start of input range.
513  * @param __last End of input range.
514  * @param __result Start of output range.
515  * @param __binary_op Function to perform summation.
516  * @return The end of the output range.
517  *
518  * Write the cumulative sum (aka prefix sum, aka scan) of the input range
519  * to the output range. Each element of the output range contains the
520  * running total of all earlier elements, using `binary_op` for summation.
521  *
522  * This function generates an "inclusive" scan, meaning the Nth element
523  * of the output range is the sum of the first N input elements,
524  * so the Nth input element is included.
525  */
526  template<typename _InputIterator, typename _OutputIterator,
527  typename _BinaryOperation>
528  _OutputIterator
529  inclusive_scan(_InputIterator __first, _InputIterator __last,
530  _OutputIterator __result, _BinaryOperation __binary_op)
531  {
532  if (__first != __last)
533  {
534  auto __init = *__first;
535  *__result++ = __init;
536  ++__first;
537  if (__first != __last)
538  __result = std::inclusive_scan(__first, __last, __result,
539  __binary_op, std::move(__init));
540  }
541  return __result;
542  }
543 
544  /** @brief Output the cumulative sum of one range to a second range
545  *
546  * @param __first Start of input range.
547  * @param __last End of input range.
548  * @param __result Start of output range.
549  * @return The end of the output range.
550  *
551  * Write the cumulative sum (aka prefix sum, aka scan) of the input range
552  * to the output range. Each element of the output range contains the
553  * running total of all earlier elements, using `std::plus<>` for summation.
554  *
555  * This function generates an "inclusive" scan, meaning the Nth element
556  * of the output range is the sum of the first N input elements,
557  * so the Nth input element is included.
558  */
559  template<typename _InputIterator, typename _OutputIterator>
560  inline _OutputIterator
561  inclusive_scan(_InputIterator __first, _InputIterator __last,
562  _OutputIterator __result)
563  { return std::inclusive_scan(__first, __last, __result, plus<>()); }
564 
565  /** @brief Output the cumulative sum of one range to a second range
566  *
567  * @param __first Start of input range.
568  * @param __last End of input range.
569  * @param __result Start of output range.
570  * @param __init Initial value.
571  * @param __binary_op Function to perform summation.
572  * @param __unary_op Function to transform elements of the input range.
573  * @return The end of the output range.
574  *
575  * Write the cumulative sum (aka prefix sum, aka scan) of the input range
576  * to the output range. Each element of the output range contains the
577  * running total of all earlier elements (and the initial value),
578  * using `__unary_op` to transform the input elements
579  * and using `__binary_op` for summation.
580  *
581  * This function generates an "exclusive" scan, meaning the Nth element
582  * of the output range is the sum of the first N-1 input elements,
583  * so the Nth input element is not included.
584  */
585  template<typename _InputIterator, typename _OutputIterator, typename _Tp,
586  typename _BinaryOperation, typename _UnaryOperation>
587  _OutputIterator
588  transform_exclusive_scan(_InputIterator __first, _InputIterator __last,
589  _OutputIterator __result, _Tp __init,
590  _BinaryOperation __binary_op,
591  _UnaryOperation __unary_op)
592  {
593  while (__first != __last)
594  {
595  auto __v = __init;
596  __init = __binary_op(__init, __unary_op(*__first));
597  ++__first;
598  *__result++ = std::move(__v);
599  }
600  return __result;
601  }
602 
603  /** @brief Output the cumulative sum of one range to a second range
604  *
605  * @param __first Start of input range.
606  * @param __last End of input range.
607  * @param __result Start of output range.
608  * @param __binary_op Function to perform summation.
609  * @param __unary_op Function to transform elements of the input range.
610  * @param __init Initial value.
611  * @return The end of the output range.
612  *
613  * Write the cumulative sum (aka prefix sum, aka scan) of the input range
614  * to the output range. Each element of the output range contains the
615  * running total of all earlier elements (and the initial value),
616  * using `__unary_op` to transform the input elements
617  * and using `__binary_op` for summation.
618  *
619  * This function generates an "inclusive" scan, meaning the Nth element
620  * of the output range is the sum of the first N input elements,
621  * so the Nth input element is included.
622  */
623  template<typename _InputIterator, typename _OutputIterator,
624  typename _BinaryOperation, typename _UnaryOperation, typename _Tp>
625  _OutputIterator
626  transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
627  _OutputIterator __result,
628  _BinaryOperation __binary_op,
629  _UnaryOperation __unary_op,
630  _Tp __init)
631  {
632  for (; __first != __last; ++__first)
633  *__result++ = __init = __binary_op(__init, __unary_op(*__first));
634  return __result;
635  }
636 
637  /** @brief Output the cumulative sum of one range to a second range
638  *
639  * @param __first Start of input range.
640  * @param __last End of input range.
641  * @param __result Start of output range.
642  * @param __binary_op Function to perform summation.
643  * @param __unary_op Function to transform elements of the input range.
644  * @return The end of the output range.
645  *
646  * Write the cumulative sum (aka prefix sum, aka scan) of the input range
647  * to the output range. Each element of the output range contains the
648  * running total of all earlier elements,
649  * using `__unary_op` to transform the input elements
650  * and using `__binary_op` for summation.
651  *
652  * This function generates an "inclusive" scan, meaning the Nth element
653  * of the output range is the sum of the first N input elements,
654  * so the Nth input element is included.
655  */
656  template<typename _InputIterator, typename _OutputIterator,
657  typename _BinaryOperation, typename _UnaryOperation>
658  _OutputIterator
659  transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
660  _OutputIterator __result,
661  _BinaryOperation __binary_op,
662  _UnaryOperation __unary_op)
663  {
664  if (__first != __last)
665  {
666  auto __init = __unary_op(*__first);
667  *__result++ = __init;
668  ++__first;
669  if (__first != __last)
670  __result = std::transform_inclusive_scan(__first, __last, __result,
671  __binary_op, __unary_op,
672  std::move(__init));
673  }
674  return __result;
675  }
676 
677  // @} group numeric_ops
678 
679 _GLIBCXX_END_NAMESPACE_VERSION
680 } // namespace std
681 
682 // Parallel STL algorithms
683 # if _PSTL_EXECUTION_POLICIES_DEFINED
684 // If <execution> has already been included, pull in implementations
685 # include <pstl/glue_numeric_impl.h>
686 # else
687 // Otherwise just pull in forward declarations
688 # include <pstl/glue_numeric_defs.h>
689 # define _PSTL_NUMERIC_FORWARD_DECLARED 1
690 # endif
691 
692 // Feature test macro for parallel algorithms
693 # define __cpp_lib_parallel_algorithm 201603L
694 #endif // C++17
695 
696 #endif /* _GLIBCXX_NUMERIC */
std::experimental::fundamentals_v2::lcm
constexpr common_type_t< _Mn, _Nn > lcm(_Mn __m, _Nn __n)
Least common multiple.
Definition: experimental/numeric:71
stl_iterator_base_types.h
std
ISO C++ entities toplevel namespace is std.
std::__detail::__lcm
constexpr common_type_t< _Mn, _Nn > __lcm(_Mn __m, _Nn __n)
Least common multiple.
Definition: numeric:112
limits
c++config.h
std::numeric_limits::max
static constexpr _Tp max() noexcept
Definition: limits:321
stl_function.h
std::numeric_limits::min
static constexpr _Tp min() noexcept
Definition: limits:317
type_traits
numeric
Parallel STL function calls corresponding to stl_numeric.h. The functions defined here mainly do case...
std::experimental::fundamentals_v2::gcd
constexpr common_type_t< _Mn, _Nn > gcd(_Mn __m, _Nn __n)
Greatest common divisor.
Definition: experimental/numeric:57
std::move
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Definition: move.h:101
stl_numeric.h