自己输入一遍代码,总是胜过仅仅阅读。
template <typename InputIterator, typename Predicate>
InputIterator Find_if(InputIterator& first, InputIterator& end, Predicate pred)
{
while( first != end && !pred (*first))
++ first;
return first;
}
template <typename Arg, typename Result>
struct unary_function{
typedef Arg argument_type;
typedef Result result_type;
};
template <typename Adapertable>
class negate_unary
{
public:
typedef typename Adapertable::argument_type Arg;
typedef typename Adapertable::result_type Result;
negate_unary(const Adapertable& ad):pred(ad){}
bool operator()(const Arg& ag) const{
return !pred(ag);
}
private:
Adapertable pred;
};
template <typename InputIterator, typename Predicate>
InputIterator Find_if(InputIterator& first, InputIterator& end, Predicate pred)
{
while( first != end && !pred (*first))
++ first;
return first;
}
template <typename Arg, typename Result>
struct unary_function{
typedef Arg argument_type;
typedef Result result_type;
};
template <typename Adapertable>
class negate_unary
{
public:
typedef typename Adapertable::argument_type Arg;
typedef typename Adapertable::result_type Result;
negate_unary(const Adapertable& ad):pred(ad){}
bool operator()(const Arg& ag) const{
return !pred(ag);
}
private:
Adapertable pred;
};