Boost logo

Boost :

From: Robert Jones (robertgbjones_at_[hidden])
Date: 2008-07-21 12:01:59


I encountered this difficulty in the context of passing lambda functors, but
on reflection I don't the lambda aspect particularly matters.

Consider this templated function

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;
}

Obviously the intent is to enquire if all members of a range satisfy the
predicate.

Now, as is, this doesn't compile, because it needs ptr_fun() on the
predicate, but then a couple of things come up.

- ptr_fun( ) requires that it's argument is a pointer-to-function
- I'd like my all_if( ) to permit functions or functors, including lambda
functors

How can this be done? Is it impossible to dress-up a standard
algorithm in this way?

Thanks, Rob.

-- 
ACCU - Professionalism in programming - http://www.accu.org

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk