Boost logo

Boost Users :

From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-07-21 12:12:09


AMDG

Robert Jones wrote:
> template <typename InputIterator, typename Predicate>
> inline bool all_if( InputIterator first, InputIterator last,
> Predicate predicate )
> {
> return std :: find_if( first, last, std :: not1( predicate ) ) == last;
> }
>
> Is it impossible to dress-up a standard
> algorithm in this way?

It's quite possible, but the std function adapters are not
up to the job. Here's a simple replacement for std::not1.
(!boost::bind(f) also works)

template<class F>
struct not_t {
   typedef bool result_type;
   template<class T>
   bool operator()(const T& t) { return(!f(t)); }
   F f;
};

template<class F>
not_t<F> not(F f) {
   not_t<F> result = { f };
   return(result);
}

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net