template <class Predicate> class binary_negate; |
C++98 |
template <class Predicate> class binary_negate : public binary_function <typename Predicate::first_argument_type, typename Predicate::second_argument_type, bool> { protected: Predicate fn_; public: explicit binary_negate ( const Predicate& pred ) : fn_ (pred) {} bool operator() (const typename Predicate::first_argument_type& x, const typename Predicate::second_argument_type& y) const { return !fn_(x,y); } }; |
成员类型 | 定义 | 注释 |
first_argument_type | T | 成员operator()中第一个参数的类型 |
second_argument_type | T | 成员operator()中第二个参数的类型 |
result_type | T | 成员operator()返回的类型 |
// binary_negate example #include <iostream> // std::cout #include <functional> // std::binary_negate, std::equal_to #include <algorithm> // std::mismatch #include <utility> // std::pair int main () { std::equal_to<int> equality; std::binary_negate < std::equal_to<int> > nonequality (equality); int foo[] = {10,20,30,40,50}; int bar[] = {0,15,30,45,60}; std::pair<int*,int*> firstmatch,firstmismatch; firstmismatch = std::mismatch (foo,foo+5,bar,equality); firstmatch = std::mismatch (foo,foo+5,bar,nonequality); std::cout << "First mismatch in bar is " << *firstmismatch.second << "\n"; std::cout << "First match in bar is " << *firstmatch.second << "\n"; return 0; } |
not2 | 返回二元函数对象的结果相反的二元函数对象(类模板) |
unary_negate | 对一元函数对象求反的类(类模板) |
binary_function | 二元函数对象基类 (类模板) |