std::modulus<void>
來自 cppreference.com
定義於標頭檔案 <functional> |
||
template<> class modulus<void>; |
(C++14 起) | |
std::modulus<void> 是 std::modulus 的一個特化,其引數和返回型別是推導的。
目錄 |
[edit] 巢狀型別
巢狀型別 | 定義 |
is_transparent
|
未指定 |
[edit] 成員函式
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).
[edit] 示例
執行此程式碼
#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 is converted into a temporary object M{42} std::modulus<M>{}(m, 42); // calls operator%(M, M) // no temporary object std::modulus<void>{}(m, 42); // calls operator%(M, int) std::modulus<void>{}(42, m); // calls operator%(int, M) }
輸出
M(42); operator%(M, M); operator%(M, int); operator%(int, M);