|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2006-02-21 12:51:48
Nico Galoppo <nico_at_[hidden]> writes:
> I'm having trouble getting make_filter_iterator and bind to work together nicely:
>
> -------------------------------------------------------------------------------
> boost::function<bool (const node_type&)> is_constraint;
> is_constraint = boost::bind(&node_type::IsConstraint, _1);
>
> boost::make_filter_iterator(is_constraint, ab.begin(), ab.end()); // ERROR:
> does not compile
> boost::make_filter_iterator(boost::bind(&node_type::IsConstraint, _1),
> ab.begin(), ab.end()); // compiles
> -------------------------------------------------------------------------------
>
> Note that ab.begin()/ab.end() return iterators to containers of shared pointers.
> See below for compiler errors.
It's actually not bind, but function. Bind contains magic that treats
shared_ptr<T> and T& the same way, but for function to take advantage
of that magic, you need to make sure its argument type is
shared_ptr<T>, not T&:
boost::function<bool (shared_ptr<node_type const>)> is_constraint
= boost::bind(&node_type::IsConstraint, _1);
boost::make_filter_iterator(is_constraint, ab.begin(), ab.end());
The hint is right here:
> Reason: cannot convert from
> 'Hybrid::Graph<node_traits>::const_node_ptr' to 'const node_type'
> with
> [
> node_traits=ArticulatedModelNodeTraits<MyTypes>
> ]
HTH,
-- Dave Abrahams Boost Consulting www.boost-consulting.com
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