template <class T> struct modulus; |
C++98 |
template <class T> struct modulus : binary_function <T,T,T> { T operator() (const T& x, const T& y) const {return x%y;} }; |
成员类型 | 定义 | 注释 |
first_argument_type | T | 成员operator()中第一个参数的类型 |
second_argument_type | T | 成员operator()中第二个参数的类型 |
result_type | T | 成员operator()返回的类型 |
T operator() (const T& x, const T& y) |
// modulus example #include <iostream> // std::cout #include <functional> // std::modulus, std::bind2nd #include <algorithm> // std::transform int main () { int numbers[]={1,2,3,4,5}; int remainders[5]; std::transform (numbers, numbers+5, remainders, std::bind2nd(std::modulus<int>(),2)); for (int i=0; i<5; i++) std::cout << numbers[i] << " is " << (remainders[i]==0?"even":"odd") << '\n'; return 0; } |
plus | 加法函数对象类(类模板) |
minus | 减法函数对象类(类模板) |
multiplies | 乘法函数对象类(类模板) |
divides | 除法函数对象类(类模板) |
negate | 取反函数对象类(类模板) |
equal_to | 用于相等比较的函数对象类(类模板) |