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()
возвращает модуль двух аргументов
(public member function)

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