This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
[numeric.ops.gcd]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.10 Generalized numeric operations [[numeric.ops]](numeric.ops#gcd)
### 26.10.14 Greatest common divisor [numeric.ops.gcd]
[🔗](#lib:gcd)
`template<class M, class N>
constexpr common_type_t<M, N> gcd(M m, N n);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13274)
*Mandates*: M and N both are integer types other thancv bool[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13279)
*Preconditions*: |m| and |n| are representable as a value of common_type_t<M, N>[.](#2.sentence-1)
[*Note [1](#note-1)*:
These requirements ensure, for example,
that gcd(m, m)=|m| is representable as a value of type M[.](#2.sentence-2)
— *end note*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13290)
*Returns*: Zero when m and n are both zero[.](#3.sentence-1)
Otherwise,
returns the greatest common divisor of |m| and |n|[.](#3.sentence-2)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13295)
*Throws*: Nothing[.](#4.sentence-1)

View File

@@ -0,0 +1,18 @@
[numeric.ops.general]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.10 Generalized numeric operations [[numeric.ops]](numeric.ops#general)
### 26.10.1 General [numeric.ops.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L12261)
[*Note [1](#note-1)*:
The use of closed ranges as well as semi-open ranges
to specify requirements throughout [[numeric.ops]](numeric.ops "26.10Generalized numeric operations") is intentional[.](#1.sentence-1)
— *end note*]

View File

@@ -0,0 +1,41 @@
[numeric.ops.lcm]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.10 Generalized numeric operations [[numeric.ops]](numeric.ops#lcm)
### 26.10.15 Least common multiple [numeric.ops.lcm]
[🔗](#lib:lcm)
`template<class M, class N>
constexpr common_type_t<M, N> lcm(M m, N n);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13309)
*Mandates*: M and N both are integer types other thancv bool[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13314)
*Preconditions*: |m| and |n| are representable as a value of common_type_t<M, N>[.](#2.sentence-1)
The least common multiple of |m| and |n| is representable as a value of type common_type_t<M, N>[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13321)
*Returns*: Zero when either m or n is zero[.](#3.sentence-1)
Otherwise, returns the least common multiple of |m| and |n|[.](#3.sentence-2)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13326)
*Throws*: Nothing[.](#4.sentence-1)

View File

@@ -0,0 +1,79 @@
[numeric.ops.midpoint]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.10 Generalized numeric operations [[numeric.ops]](numeric.ops#midpoint)
### 26.10.16 Midpoint [numeric.ops.midpoint]
[🔗](#lib:midpoint)
`template<class T>
constexpr T midpoint(T a, T b) noexcept;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13339)
*Constraints*: T is an arithmetic type other than bool[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13343)
*Returns*: Half the sum of a and b[.](#2.sentence-1)
If T is an integer type and the sum is odd,
the result is rounded towards a[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13349)
*Remarks*: No overflow occurs[.](#3.sentence-1)
If T is a floating-point type, at most one inexact operation occurs[.](#3.sentence-2)
[🔗](#lib:midpoint_)
`template<class T>
constexpr T* midpoint(T* a, T* b);
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13361)
*Constraints*: T is an object type[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13365)
*Mandates*: T is a complete type[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13369)
*Preconditions*: a and b point to, respectively,
elements i and j of the same array object x[.](#6.sentence-1)
[*Note [1](#note-1)*:
As specified in [[basic.compound]](basic.compound "6.9.4Compound types"),
an object that is not an array element
is considered to belong to a single-element array for this purpose and
a pointer past the last element of an array of n elements
is considered to be equivalent to a pointer
to a hypothetical array element n for this purpose[.](#6.sentence-2)
— *end note*]
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13382)
*Returns*: A pointer to array element i+j−i2 of x,
where the result of the division is truncated towards zero[.](#7.sentence-1)

View File

@@ -0,0 +1,74 @@
[numeric.ops.overview]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.9 Header <numeric> synopsis [numeric.ops.overview]
[🔗](#header:%3cnumeric%3e)
// mostly freestandingnamespace std {// [[accumulate]](accumulate "26.10.3Accumulate"), accumulatetemplate<class InputIterator, class T>constexpr T accumulate(InputIterator first, InputIterator last, T init); template<class InputIterator, class T, class BinaryOperation>constexpr T accumulate(InputIterator first, InputIterator last, T init,
BinaryOperation binary_op); // [[reduce]](reduce "26.10.4Reduce"), reducetemplate<class InputIterator>constexpr typename iterator_traits<InputIterator>::value_type
reduce(InputIterator first, InputIterator last); template<class InputIterator, class T>constexpr T reduce(InputIterator first, InputIterator last, T init); template<class InputIterator, class T, class BinaryOperation>constexpr T reduce(InputIterator first, InputIterator last, T init,
BinaryOperation binary_op); template<class ExecutionPolicy, class ForwardIterator>typename iterator_traits<ForwardIterator>::value_type
reduce(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5Parallel algorithm overloads") ForwardIterator first, ForwardIterator last); template<class ExecutionPolicy, class ForwardIterator, class T> T reduce(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5Parallel algorithm overloads") ForwardIterator first, ForwardIterator last, T init); template<class ExecutionPolicy, class ForwardIterator, class T, class BinaryOperation> T reduce(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5Parallel algorithm overloads") ForwardIterator first, ForwardIterator last, T init, BinaryOperation binary_op); // [[inner.product]](inner.product "26.10.5Inner product"), inner producttemplate<class InputIterator1, class InputIterator2, class T>constexpr T inner_product(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init); template<class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2>constexpr T inner_product(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init,
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); // [[transform.reduce]](transform.reduce "26.10.6Transform reduce"), transform reducetemplate<class InputIterator1, class InputIterator2, class T>constexpr T transform_reduce(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init); template<class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2>constexpr T transform_reduce(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init,
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); template<class InputIterator, class T, class BinaryOperation, class UnaryOperation>constexpr T transform_reduce(InputIterator first, InputIterator last, T init,
BinaryOperation binary_op, UnaryOperation unary_op); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T> T transform_reduce(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5Parallel algorithm overloads") ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, T init); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T, class BinaryOperation1, class BinaryOperation2> T transform_reduce(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5Parallel algorithm overloads") ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, T init,
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); template<class ExecutionPolicy, class ForwardIterator, class T, class BinaryOperation, class UnaryOperation> T transform_reduce(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5Parallel algorithm overloads") ForwardIterator first, ForwardIterator last, T init,
BinaryOperation binary_op, UnaryOperation unary_op); // [[partial.sum]](partial.sum "26.10.7Partial sum"), partial sumtemplate<class InputIterator, class OutputIterator>constexpr OutputIterator
partial_sum(InputIterator first, InputIterator last,
OutputIterator result); template<class InputIterator, class OutputIterator, class BinaryOperation>constexpr OutputIterator
partial_sum(InputIterator first, InputIterator last,
OutputIterator result, BinaryOperation binary_op); // [[exclusive.scan]](exclusive.scan "26.10.8Exclusive scan"), exclusive scantemplate<class InputIterator, class OutputIterator, class T>constexpr OutputIterator
exclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, T init); template<class InputIterator, class OutputIterator, class T, class BinaryOperation>constexpr OutputIterator
exclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, T init, BinaryOperation binary_op); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T> ForwardIterator2
exclusive_scan(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5Parallel algorithm overloads") ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result, T init); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T, class BinaryOperation> ForwardIterator2
exclusive_scan(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5Parallel algorithm overloads") ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result, T init, BinaryOperation binary_op); // [[inclusive.scan]](inclusive.scan "26.10.9Inclusive scan"), inclusive scantemplate<class InputIterator, class OutputIterator>constexpr OutputIterator
inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result); template<class InputIterator, class OutputIterator, class BinaryOperation>constexpr OutputIterator
inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, BinaryOperation binary_op); template<class InputIterator, class OutputIterator, class BinaryOperation, class T>constexpr OutputIterator
inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, BinaryOperation binary_op, T init); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> ForwardIterator2
inclusive_scan(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5Parallel algorithm overloads") ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryOperation> ForwardIterator2
inclusive_scan(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5Parallel algorithm overloads") ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result, BinaryOperation binary_op); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryOperation, class T> ForwardIterator2
inclusive_scan(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5Parallel algorithm overloads") ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result, BinaryOperation binary_op, T init); // [[transform.exclusive.scan]](transform.exclusive.scan "26.10.10Transform exclusive scan"), transform exclusive scantemplate<class InputIterator, class OutputIterator, class T, class BinaryOperation, class UnaryOperation>constexpr OutputIterator
transform_exclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, T init,
BinaryOperation binary_op, UnaryOperation unary_op); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T, class BinaryOperation, class UnaryOperation> ForwardIterator2
transform_exclusive_scan(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5Parallel algorithm overloads") ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result, T init,
BinaryOperation binary_op, UnaryOperation unary_op); // [[transform.inclusive.scan]](transform.inclusive.scan "26.10.11Transform inclusive scan"), transform inclusive scantemplate<class InputIterator, class OutputIterator, class BinaryOperation, class UnaryOperation>constexpr OutputIterator
transform_inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result,
BinaryOperation binary_op, UnaryOperation unary_op); template<class InputIterator, class OutputIterator, class BinaryOperation, class UnaryOperation, class T>constexpr OutputIterator
transform_inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result,
BinaryOperation binary_op, UnaryOperation unary_op, T init); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryOperation, class UnaryOperation> ForwardIterator2
transform_inclusive_scan(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5Parallel algorithm overloads") ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result, BinaryOperation binary_op,
UnaryOperation unary_op); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryOperation, class UnaryOperation, class T> ForwardIterator2
transform_inclusive_scan(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5Parallel algorithm overloads") ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result,
BinaryOperation binary_op, UnaryOperation unary_op, T init); // [[adjacent.difference]](adjacent.difference "26.10.12Adjacent difference"), adjacent differencetemplate<class InputIterator, class OutputIterator>constexpr OutputIterator
adjacent_difference(InputIterator first, InputIterator last,
OutputIterator result); template<class InputIterator, class OutputIterator, class BinaryOperation>constexpr OutputIterator
adjacent_difference(InputIterator first, InputIterator last,
OutputIterator result, BinaryOperation binary_op); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> ForwardIterator2
adjacent_difference(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5Parallel algorithm overloads") ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryOperation> ForwardIterator2
adjacent_difference(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5Parallel algorithm overloads") ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result, BinaryOperation binary_op); // [[numeric.iota]](numeric.iota "26.10.13Iota"), iotatemplate<class ForwardIterator, class T>constexpr void iota(ForwardIterator first, ForwardIterator last, T value); namespace ranges {template<class O, class T>using [iota_result](#lib:iota_result "26.9Header <numeric> synopsis[numeric.ops.overview]") = out_value_result<O, T>; template<[input_or_output_iterator](iterator.concept.iterator#concept:input_or_output_iterator "24.3.4.6Concept input_­or_­output_­iterator[iterator.concept.iterator]") O, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<O> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") T>requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<O, const T&>constexpr iota_result<O, T> iota(O first, S last, T value); template<[weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") T, [output_range](range.refinements#concept:output_range "25.4.6Other range refinements[range.refinements]")<const T&> R>constexpr iota_result<borrowed_iterator_t<R>, T> iota(R&& r, T value); }// [[numeric.ops.gcd]](numeric.ops.gcd "26.10.14Greatest common divisor"), greatest common divisortemplate<class M, class N>constexpr common_type_t<M, N> gcd(M m, N n); // [[numeric.ops.lcm]](numeric.ops.lcm "26.10.15Least common multiple"), least common multipletemplate<class M, class N>constexpr common_type_t<M, N> lcm(M m, N n); // [[numeric.ops.midpoint]](numeric.ops.midpoint "26.10.16Midpoint"), midpointtemplate<class T>constexpr T midpoint(T a, T b) noexcept; template<class T>constexpr T* midpoint(T* a, T* b); // [[numeric.sat]](numeric.sat "26.10.17Saturation arithmetic"), saturation arithmetictemplate<class T>constexpr T add_sat(T x, T y) noexcept; template<class T>constexpr T sub_sat(T x, T y) noexcept; template<class T>constexpr T mul_sat(T x, T y) noexcept; template<class T>constexpr T div_sat(T x, T y) noexcept; template<class T, class U>constexpr T saturate_cast(U x) noexcept;}