template <class Predicate> class unary_negate; |
C++98 |
template <class Predicate> class unary_negate : public unary_function <typename Predicate::argument_type,bool> { protected: Predicate fn_; public: explicit unary_negate (const Predicate& pred) : fn_ (pred) {} bool operator() (const typename Predicate::argument_type& x) const {return !fn_(x);} }; |
成员类型 | 定义 | 注释 |
argument_type | T | 成员operator()中参数的类型 |
result_type | T | 成员operator()返回的类型 |
// unary_negate example #include <iostream> // std::cout #include <functional> // std::unary_negate #include <algorithm> // std::count_if struct IsOdd_class { bool operator() (const int& x) const {return x%2==1;} typedef int argument_type; } IsOdd_object; int main () { std::unary_negate<IsOdd_class> IsEven_object (IsOdd_object); int values[] = {1,2,3,4,5}; int cx; cx = std::count_if ( values, values+5, IsEven_object ); std::cout << "There are " << cx << " elements with even values.\n"; return 0; } |
not1 | 返回一元函数对象的结果相反的一元函数对象(类模板) |
binary_negate | 对二元函数对象求反的类(类模板) |