template <class T> struct divides;
123
template <class T> struct divides : binary_function <T,T,T> { T operator() (const T& x, const T& y) const {return x/y;} };
123456
template <class T> struct divides { 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
123456789101112131415
// divides example #include <iostream> // std::cout #include <functional> // std::divides #include <algorithm> // std::transform int main () { int first[]={10,40,90,40,10}; int second[]={1,2,3,4,5}; int results[5]; std::transform (first, first+5, second, results, std::divides<int>()); for (int i=0; i<5; i++) std::cout << results[i] << ' '; std::cout << '\n'; return 0; }
10 20 30 10 2