filter_iterator question
Hello all : I have a filter_iterator question. I'm wondering if, conceptualy, I can construct an FI doing something like the following : typedef boost::filter_iterator< boost::bind( boost::mem_fn( &MyObject::HasQuality ), boost::ref( quality ) ), MyIterator > FilteredIterator; Instead of defining an explicit functor like this : struct MyFunctor { bool operator()( const MyObject& obj ) const { etc } }; and the FI like this : typedef boost::filter_iterator< MyFunctor, MyIterator > FilteredIterator; Gosh! Writing functors is flipping waste of time! Has anyone used the former construct instead? Thanks in advance! SGA
steve ahlgren
Hello all :
I have a filter_iterator question.
I'm wondering if, conceptualy, I can construct an FI doing something like the following :
typedef boost::filter_iterator< boost::bind( boost::mem_fn( &MyObject::HasQuality ), boost::ref( quality ) ), MyIterator > FilteredIterator;
You don't need mem_fn; bind will handle that implicitly. But sure, that'll work in principle. Just not in practice ;-). The problem is that you're putting a runtime expression in the template where a type is supposed to be. On the other hand, you could use make_filter_iterator to generate an appropriate iterator object. http://www.boost.org/libs/iterator/doc/filter_iterator.html#filter-iterator-... -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams
-
steve ahlgren