class template
<functional>
std::minus
template <class T> struct minus;
Subtraction function object class
Binary function object class whose call returns the result of subtracting its second argument from its first argument (as returned by the binary operator -).
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 function call.
It is defined with the same behavior as:
1 2 3
|
template <class T> struct minus : binary_function <T,T,T> {
T operator() (const T& x, const T& y) const {return x-y;}
};
|
1 2 3 4 5 6
|
template <class T> struct minus {
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;
};
|
Objects of this class can be used on standard algorithms such as transform or accumulate.
Template parameters
- T
- Type of the arguments and return type of the functional call.
The type shall support the operation (binary operator-).
Member types
member type | definition | notes |
first_argument_type | T | Type of the first argument in member operator() |
second_argument_type | T | Type of the second argument in member operator() |
result_type | T | Type returned by member operator() |
Member functions
- T operator() (const T& x, const T& y)
- Member function returning the subtraction of its arguments (
x-y
).
Example
1 2 3 4 5 6 7 8 9 10 11 12
|
// minus example
#include <iostream> // std::cout
#include <functional> // std::minus
#include <algorithm> // std::transform
int main () {
int numbers[]={10,20,30};
int result;
result = std::accumulate (numbers, numbers+3, 100, std::minus<int>());
std::cout << "The result of 100-10-20-30 is " << result << ".\n";
return 0;
}
|
Output:
The result of 100-10-20-30 is 40.
|
See also
- plus
- Addition function object class (class template
)
- multiplies
- Multiplication function object class (class template
)
- divides
- Division function object class (class template
)
- modulus
- Modulus function object class (class template
)
- negate
- Negative function object class (class template
)
- equal_to
- Function object class for equality comparison (class template
)