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 unspecified

メンバー関数

operator()
2つの引数の剰余を返す
(公開メンバ関数)

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