|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2006-02-22 10:35:07
Nico Galoppo <nico_at_[hidden]> writes:
> Thanks, that works like a charm. Unfortunately, dereferencing the created
> iterator gives more trouble:
>
> boost::function<bool (shared_ptr<node_type const>)> is_constraint
> = boost::bind(&node_type::IsConstraint, _1);
> typedef boost::filter_iterator<boost::function<bool (shared_ptr<node_type
> const>)>, articulated_model_type::node_df_traversal_iterator> joint_node_iterator;
>
> joint_node_iterator jointnode
> = boost::make_filter_iterator(is_constraint, ab.begin(), ab.end());
>
> std::cout << jointnode->Model(); ///< this line fails to compile
>
> There seems to be a problem with const-ness (see below).
It's not a constness problem, exactly. The problem is that the result
of
*ab.begin()
is an rvalue (i.e. returned by value, not by reference). Yet the
filter_iterator thinks it is iterating over lvalues: its reference
type is Hybrid::Graph<node_traits>::const_node_ptr&, and the compiler
is complaining that you can't initialize such a reference with a
non-lvalue. It's hard to come up with a complete analysis with the
little information I have here, but I believe
Hybrid::Graph<Hybrid::ArticulatedModelNodeTraits<MyTypes> >::node_df_traversal_iterator
is misreporting its reference type or its category. An iterator whose
operator* returns by value cannot be a forward iterator; it can only
be an input iterator.
-- 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