Re: Iterator adaptor interoperability
Dave Abrahams wrote:
Your best bet is to write an type generator: template <class Iterator> struct simple_iterator { typedef boost::transform_iterator< do_nothing< typename Iterator::value_type > , Iterator > type; };
Thank you for the quick and clear reply! I'm now having a very similar problem with a slightly more complicated example (that builds on the first): template< class Iterator > struct harder_iterator { typedef simple_iterator< Iterator >::type inner_type; typedef boost::indirect_iterator< inner_type > type; static type Create( const Iterator& iter ) { return type( inner_type( iter ) ); } }; This "composite" iterator not only has problems with comparison, but assignment from non-const to const as well. Is there a way to handle this case? Thanks, Kris __________________________________ Do you Yahoo!? Yahoo! Mail SpamGuard - Read only the mail you want. http://antispam.yahoo.com/tools
Kris Braun
Dave Abrahams wrote:
Your best bet is to write an type generator: template <class Iterator> struct simple_iterator { typedef boost::transform_iterator< do_nothing< typename Iterator::value_type > , Iterator > type; };
Thank you for the quick and clear reply! I'm now having a very similar problem with a slightly more complicated example (that builds on the first):
template< class Iterator > struct harder_iterator { typedef simple_iterator< Iterator >::type inner_type; typedef boost::indirect_iterator< inner_type > type;
static type Create( const Iterator& iter ) { return type( inner_type( iter ) ); } };
This "composite" iterator not only has problems with comparison, but assignment from non-const to const as well. Is there a way to handle this case?
Need more details. Post a reproducible test that fails compilation and I might be able to solve your problem. -- Dave Abrahams Boost Consulting www.boost-consulting.com
--- David Abrahams
Need more details. Post a reproducible test that fails compilation and I might be able to solve your problem.
Okay, here's all the code for the test:
#include <map>
#include
const_iterator_generator; typedef iterator_generator::type iterator; typedef const_iterator_generator::type const_iterator;
struct Foo {
iterator begin( void )
{ return iterator_generator::Create( m.begin(
) ); }
iterator end( void )
{ return iterator_generator::Create( m.end( )
); }
MapType m;
};
void foo( void )
{
Foo f;
for( const_iterator i = f.begin( ); i != f.end( );
++i ) { }
}
When compiled with VC7.1, this produces:
src\util\test.cpp(53) : error C2440: 'initializing' :
cannot convert from 'iterator' to
boost::indirect_iterator<Iterator>'
with
[
Iterator=pointer_map_iterator
Kris Braun
--- David Abrahams
wrote: Need more details. Post a reproducible test that fails compilation and I might be able to solve your problem.
Okay, here's all the code for the test:
Thomas sez:
From: Thomas Witt
--- David Abrahams
wrote: Need more details. Post a reproducible test that fails compilation and I might be able to solve your problem. Okay, here's all the code for the test:
Either I am going nuts or this is a compiler problem adding the
following line before foo makes the code compile for me
BOOST_STATIC_ASSERT((boost::is_convertible
void foo( void ) { Foo f; for( const_iterator i = f.begin( ); i != f.end( ); ++i ) { } }
Could you please check whether you get the same result. Thomas -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams
-
Kris Braun