[numeric.ops.gcd] states:
template<class M, class N> constexpr common_type_t<M, N> gcd(M m, N n);Mandates:
MandNboth are integer types other than cvbool.
While doing so is not very useful, it seems permitted to call:
std::gcd<const int, volatile int>(0, 0);
That is because const int is an arithmetic type.
However, [algorithms.requirements] paragraph 15 states:
The well-formedness and behavior of a call to an algorithm with an explicitly-specified template argument list is unspecified, except where explicitly stated otherwise.
This begs the question: Is std::gcd an algorithm, and more generally, what is an algorithm? I was unable to find a definition of "algorithm", and since [numeric.ops.gcd] is nested in [algorithm], it may be considered one.
Yes, std::gcd is an algorithm.
Table 83 (algorithms library summary, reproduced-ish below) lists numeric.ops a.k.a. the <numeric> header as part of the library, and std::gcd falls under it (numeric.ops.gcd)
| Subclause | Description | Header |
|---|---|---|
| [algorithms.requirements] | Algorithms requirements | |
| [algorithms.parallel] | Parallel algorithms | <execution> |
| [algorithms.results] | Algorithm result types | <algorithm> |
| [alg.nonmodifying] | Non-modifying sequence operations | |
| [alg.modifying.operations] | Mutating sequence operations | |
| [alg.sorting] | Sorting and related operations | |
| [numeric.ops] | Generalized numeric operations | <numeric> |
| [specialized.algorithms] | Specialized <memory> algorithms |
<memory> |
| [alg.rand] | Specialized <random> algorithms |
<random> |
| [alg.c.library] | C library algorithms | <cstdlib> |
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With