David Abrahams wrote:
I'm having trouble getting make_filter_iterator and bind to work together nicely:
-------------------------------------------------------------------------------
boost::function 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)> is_constraint
= boost::bind(&node_type::IsConstraint, _1);
boost::make_filter_iterator(is_constraint, ab.begin(), ab.end());
Thanks, that works like a charm. Unfortunately, dereferencing the created
iterator gives more trouble:
boost::function)> is_constraint
= boost::bind(&node_type::IsConstraint, _1);
typedef boost::filter_iterator)>, 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).
Thanks again.
--nico
------------------------------------------------------------------------------
d:\dev\boost_1_33_1\boost\iterator\iterator_adaptor.hpp(307) : error C2440:
'return' : cannot convert from 'Hybrid::Graph::const_node_ptr' to
'boost::iterator_facade::reference'
with
[
node_traits=Hybrid::ArticulatedModelNodeTraits<MyTypes>
]
and
[
Derived=boost::filter_iterator::node_type>)>,Hybrid::Graph::node_df_traversal_iterator>,
Value=boost::iterator_value::node_df_traversal_iterator>::type,
CategoryOrTraversal=boost::mpl::identityboost::forward_traversal_tag::type,
Reference=boost::iterator_reference::node_df_traversal_iterator>::type,
Difference=boost::iterator_difference::node_df_traversal_iterator>::type
]
A reference that is not to 'const' cannot be bound to a non-lvalue
d:\dev\boost_1_33_1\boost\iterator\iterator_adaptor.hpp(307) : while
compiling class-template member function
'boost::iterator_facade::reference
boost::iterator_adaptor::dereference(void)
const'
with
[
Derived=boost::filter_iterator::node_type>)>,Hybrid::Graph::node_df_traversal_iterator>,
Value=boost::iterator_value::node_df_traversal_iterator>::type,
CategoryOrTraversal=boost::mpl::identityboost::forward_traversal_tag::type,
Reference=boost::iterator_reference::node_df_traversal_iterator>::type,
Difference=boost::iterator_difference::node_df_traversal_iterator>::type,
Base=Hybrid::Graph::node_df_traversal_iterator,
Traversal=boost::mpl::if_boost::forward_traversal_tag::type,boost::random_access_traversal_tag>,boost::bidirectional_traversal_tag,boost::use_default>::type
]
d:\dev\boost_1_33_1\boost\iterator\filter_iterator.hpp(46) : see
reference to class template instantiation
'boost::iterator_adaptor' being compiled
with
[
Derived=boost::filter_iterator::node_type>)>,Hybrid::Graph::node_df_traversal_iterator>,
Base=Hybrid::Graph::node_df_traversal_
iterator,
Value=boost::use_default,
Traversal=boost::mpl::if_boost::forward_traversal_tag::type,boost::random_access_traversal_tag>,boost::bidirectional_traversal_tag,boost::use_default>::type
]
d:\dev\Hybrid\Tests\Graph\main.cpp(398) : see reference to class
template instantiation 'boost::filter_iterator' being compiled
with
[
Predicate=boost::function::node_type>)>,
Iterator=Hybrid::Graph::node_df_traversal_iterator
]
--
nico galoppo von borries @ address: 105 creel st., chapel hill
comp. graphics phd. student @ north carolina, 27516 USA
UNC, chapel hill @ phone: +1 (919) 962-1898 (office)
@ +1 (919) 942-7609 (home)
@ email: nico at cs dot unc dot edu
@ homepage: http://www.cs.unc.edu/~nico
--- debian linux :: vim powered