template <class T> struct modulus;
123
template <class T> struct modulus : binary_function <T,T,T> { T operator() (const T& x, const T& y) const {return x%y;} };
123456
template <class T> struct modulus { T operator() (const T& x, const T& y) const {return x%y;} typedef T first_argument_type; typedef T second_argument_type; typedef T result_type; };
operator()
x%y
12345678910111213
// 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; }
1 is odd 2 is even 3 is odd 4 is even 5 is odd