std:: modulus<void>
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Old binders and adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<functional>
|
||
|
template
<>
class modulus < void > ; |
(C++14 起) | |
std:: modulus < void > 是 std::modulus 的特化版本,其参数和返回类型由编译器自动推导。
目录 |
嵌套类型
| 嵌套类型 | 定义 |
is_transparent
|
未指定 |
成员函数
|
operator()
|
返回两个参数的模数
(公开成员函数) |
std::modulus<void>:: operator()
|
template
<
class
T,
class
U
>
constexpr
auto
operator
(
)
(
T
&&
lhs, U
&&
rhs
)
const
|
||
返回 lhs 除以 rhs 的余数。
参数
| lhs, rhs | - | 用于相除的值 |
返回值
std:: forward < T > ( lhs ) % std:: forward < U > ( rhs ) 。
示例
#include <functional> #include <iostream> struct M { M(int x) { std::cout << "M(" << x << ");\n"; } M() {} }; auto operator%(M, M) { std::cout << "operator%(M, M);\n"; return M{}; } auto operator%(M, int) { std::cout << "operator%(M, int);\n"; return M{}; } auto operator%(int, M) { std::cout << "operator%(int, M);\n"; return M{}; } int main() { M m; // 42被转换为临时对象 M{42} std::modulus<M>{}(m, 42); // 调用 operator%(M, M) // 无临时对象 std::modulus<void>{}(m, 42); // 调用 operator%(M, int) std::modulus<void>{}(42, m); // 调用 operator%(int, M) }
输出:
M(42); operator%(M, M); operator%(M, int); operator%(int, M);