Files
2025-10-25 03:02:53 +03:00

269 lines
7.3 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[arithmetic.operations]
# 22 General utilities library [[utilities]](./#utilities)
## 22.10 Function objects [[function.objects]](function.objects#arithmetic.operations)
### 22.10.7 Arithmetic operations [arithmetic.operations]
#### [22.10.7.1](#general) General [[arithmetic.operations.general]](arithmetic.operations.general)
[1](#general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11999)
The library provides basic function object classes for all of the arithmetic
operators in the language ([[expr.mul]](expr.mul "7.6.5Multiplicative operators"), [[expr.add]](expr.add "7.6.6Additive operators"))[.](#general-1.sentence-1)
#### [22.10.7.2](#plus) Class template plus [[arithmetic.operations.plus]](arithmetic.operations.plus)
[🔗](#lib:plus)
`template<class T = void> struct plus {
constexpr T operator()(const T& x, const T& y) const;
};
`
[🔗](#lib:operator(),plus)
`constexpr T operator()(const T& x, const T& y) const;
`
[1](#plus-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L12018)
*Returns*: x + y[.](#plus-1.sentence-1)
[🔗](#lib:plus%3c%3e)
`template<> struct plus<void> {
template<class T, class U> constexpr auto operator()(T&& t, U&& u) const
-> decltype(std::forward<T>(t) + std::forward<U>(u));
using is_transparent = unspecified;
};
`
[🔗](#lib:operator(),plus%3c%3e)
`template<class T, class U> constexpr auto operator()(T&& t, U&& u) const
-> decltype(std::forward<T>(t) + std::forward<U>(u));
`
[2](#plus-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L12040)
*Returns*: std::forward<T>(t) + std::forward<U>(u)[.](#plus-2.sentence-1)
#### [22.10.7.3](#minus) Class template minus [[arithmetic.operations.minus]](arithmetic.operations.minus)
[🔗](#lib:minus)
`template<class T = void> struct minus {
constexpr T operator()(const T& x, const T& y) const;
};
`
[🔗](#lib:operator(),minus)
`constexpr T operator()(const T& x, const T& y) const;
`
[1](#minus-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L12060)
*Returns*: x - y[.](#minus-1.sentence-1)
[🔗](#lib:minus%3c%3e)
`template<> struct minus<void> {
template<class T, class U> constexpr auto operator()(T&& t, U&& u) const
-> decltype(std::forward<T>(t) - std::forward<U>(u));
using is_transparent = unspecified;
};
`
[🔗](#lib:operator(),minus%3c%3e)
`template<class T, class U> constexpr auto operator()(T&& t, U&& u) const
-> decltype(std::forward<T>(t) - std::forward<U>(u));
`
[2](#minus-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L12082)
*Returns*: std::forward<T>(t) - std::forward<U>(u)[.](#minus-2.sentence-1)
#### [22.10.7.4](#multiplies) Class template multiplies [[arithmetic.operations.multiplies]](arithmetic.operations.multiplies)
[🔗](#lib:multiplies)
`template<class T = void> struct multiplies {
constexpr T operator()(const T& x, const T& y) const;
};
`
[🔗](#lib:operator(),multiplies)
`constexpr T operator()(const T& x, const T& y) const;
`
[1](#multiplies-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L12102)
*Returns*: x * y[.](#multiplies-1.sentence-1)
[🔗](#lib:multiplies%3c%3e)
`template<> struct multiplies<void> {
template<class T, class U> constexpr auto operator()(T&& t, U&& u) const
-> decltype(std::forward<T>(t) * std::forward<U>(u));
using is_transparent = unspecified;
};
`
[🔗](#lib:operator(),multiplies%3c%3e)
`template<class T, class U> constexpr auto operator()(T&& t, U&& u) const
-> decltype(std::forward<T>(t) * std::forward<U>(u));
`
[2](#multiplies-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L12124)
*Returns*: std::forward<T>(t) * std::forward<U>(u)[.](#multiplies-2.sentence-1)
#### [22.10.7.5](#divides) Class template divides [[arithmetic.operations.divides]](arithmetic.operations.divides)
[🔗](#lib:divides)
`template<class T = void> struct divides {
constexpr T operator()(const T& x, const T& y) const;
};
`
[🔗](#lib:operator(),divides)
`constexpr T operator()(const T& x, const T& y) const;
`
[1](#divides-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L12144)
*Returns*: x / y[.](#divides-1.sentence-1)
[🔗](#lib:divides%3c%3e)
`template<> struct divides<void> {
template<class T, class U> constexpr auto operator()(T&& t, U&& u) const
-> decltype(std::forward<T>(t) / std::forward<U>(u));
using is_transparent = unspecified;
};
`
[🔗](#lib:operator(),divides%3c%3e)
`template<class T, class U> constexpr auto operator()(T&& t, U&& u) const
-> decltype(std::forward<T>(t) / std::forward<U>(u));
`
[2](#divides-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L12166)
*Returns*: std::forward<T>(t) / std::forward<U>(u)[.](#divides-2.sentence-1)
#### [22.10.7.6](#modulus) Class template modulus [[arithmetic.operations.modulus]](arithmetic.operations.modulus)
[🔗](#lib:modulus)
`template<class T = void> struct modulus {
constexpr T operator()(const T& x, const T& y) const;
};
`
[🔗](#lib:operator(),modulus)
`constexpr T operator()(const T& x, const T& y) const;
`
[1](#modulus-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L12186)
*Returns*: x % y[.](#modulus-1.sentence-1)
[🔗](#lib:modulus%3c%3e)
`template<> struct modulus<void> {
template<class T, class U> constexpr auto operator()(T&& t, U&& u) const
-> decltype(std::forward<T>(t) % std::forward<U>(u));
using is_transparent = unspecified;
};
`
[🔗](#lib:operator(),modulus%3c%3e)
`template<class T, class U> constexpr auto operator()(T&& t, U&& u) const
-> decltype(std::forward<T>(t) % std::forward<U>(u));
`
[2](#modulus-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L12208)
*Returns*: std::forward<T>(t) % std::forward<U>(u)[.](#modulus-2.sentence-1)
#### [22.10.7.7](#negate) Class template negate [[arithmetic.operations.negate]](arithmetic.operations.negate)
[🔗](#lib:negate)
`template<class T = void> struct negate {
constexpr T operator()(const T& x) const;
};
`
[🔗](#lib:operator(),negate)
`constexpr T operator()(const T& x) const;
`
[1](#negate-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L12228)
*Returns*: -x[.](#negate-1.sentence-1)
[🔗](#lib:negate%3c%3e)
`template<> struct negate<void> {
template<class T> constexpr auto operator()(T&& t) const
-> decltype(-std::forward<T>(t));
using is_transparent = unspecified;
};
`
[🔗](#lib:operator(),negate%3c%3e)
`template<class T> constexpr auto operator()(T&& t) const
-> decltype(-std::forward<T>(t));
`
[2](#negate-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L12250)
*Returns*: -std::forward<T>(t)[.](#negate-2.sentence-1)