Namespaces
Variants

std:: modulus<void>

From cppreference.net
Utilities library
Function objects
Function invocation
(C++17) (C++23)
Identity function object
(C++20)
Old binders and adaptors
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
( until C++17* ) ( until C++17* )
( until C++17* ) ( until C++17* )

( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
定义于头文件 <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

- > 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);