C ++ STL objects of built-in functions

STL has built some of the function object. Divided into: arithmetic function object class, relational operators function object class, the class logic operation functor. These objects functor generated, general usage and function exactly the same, of course, we can also produce unnamed temporary objects to fulfill the function function. Use the built-in function objects need to include headers #include <functional>.

6 arithmetic function object class, in addition to negate is a unary, binary operations are other.
template <class T> T plus < T> // adder functor
template <class T> T minute < T> // subtractor functor
template <class T> T multiplies < T> // multiply functor
template <class T> T divides <T> // division functor
template <class T> T modulus < T> // take mimic the function
template <class T> T negate < T> // negated functor
six relational operator function object class, each of which is binary operations.
template <class T> bool equal_to < T> // equal
template <class T> bool not_equal_to < T> // not equal
template <class T> bool greater < T> // greater than
template <class T> bool greater_equal < T> greater than or equal //
template <class T> bool less < T> // less than
template <class T> bool less_equal < T> // less
logical operation type operation function, It is not unary, binary operation for the rest.
template <class T> bool logical_and < T> // logic
template <class T> bool logical_or < T> // logical OR
template<class T> bool logical_not<T>//逻辑非

#include <iostream>
#include <functional>
using namespace std;

int main()
{
    plus<int> myplus;
    cout << myplus(10, 20) << endl;
    getchar();
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/duxie/p/10939677.html