std::modulus<void>
来自cppreference.com
<tbody>
</tbody>
| 在标头 <functional> 定义
|
||
template<> class modulus<void>; |
(C++14 起) | |
std::modulus<void> 是会推导形参类型和返回类型的 std::modulus 特化。
嵌套类型
| 嵌套类型 | 定义 |
is_transparent
|
未指定 |
成员函数
| 返回两个实参的模 (公开成员函数) |
std::modulus<void>::operator()
<tbody> </tbody> template< class T, class U > constexpr auto operator()( T&& lhs, U&& rhs ) const -> decltype(std::forward<T>(lhs) % std::forward<U>(rhs)); |
||
返回 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);