Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-01-16 08:21:59


"Markus Pesti" <news1_at_[hidden]> writes:

> I can't find any good documentation about boost::mpl::find_if.

http://www.mywikinet.com/mpl/ref/Reference/find_if.html

> The syntax is different to that of std::find_if

that's because it's only an analogy. mpl::find_if is not a function;
it's a metafunction which is evaluated entirely at compile-time.

> and std::find_if cannot be applied to lists of
> boost::shared_ptr's.

Why do you say that?

> So I created my own find_if by modifying the std one.:
<snip>
> That works fine, but I don't know whether that is o.k. to do so. Or is there
> a better way?

For a better way, see the Boost.Lambda library.

Or you can use the indirect iterator adaptor from the boost sandbox (boost/iterator/iterator_adaptors.hpp)

bool find(const std::list<boost::shared_ptr<A> >& Alist, int v) {
 return std::::find_if(
        , make_indirect_iterator(Alist.begin())
        , make_indirect_iterator(Alist.end())
        A(v)) != Alist.end();
}

-- 
                       David Abrahams
   dave_at_[hidden] * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution

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