class template

std::divides

<functional>
template <class T> struct divides;
Division function object class
This class defines function objects for the division arithmetic operation.

Generically, function objects are instances of a class with member function operator() defined. This member function allows the object to be used with the same syntax as a regular function call, and therefore it can be used in templates instead of a pointer to a function.

divides has its operator() member defined such that it returns the quotient of dividing its first argument by the second.

This class is derived from binary_function and is defined as:

1
2
3
4
template <class T> struct divides : binary_function <T,T,T> {
  T operator() (const T& x, const T& y) const
    {return x/y;}
};


Objects of this class can be used with some standard algorithms such as transform or accumulate.

Members

T operator() (const T& x, const T& y)
Member function returning the quotient of x/y.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// divides example
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;

int main () {
  int first[]={10,40,90,40,10};
  int second[]={1,2,3,4,5};
  int results[5];
  transform ( first, first+5, second, results, divides<int>() );
  for (int i=0; i<5; i++)
	  cout << results[i] << " ";
  cout << endl;
  return 0;
}


Output:

10 20 30 10 2

See also