Iterator adaptor interoperability
Hello,
I've spent the day trying to get my iterators working
after upgrading to 1.31.0. I'm almost there, but I
can't seem to get const and non-const versions to
compare with each other. I've tried about everything I
can think of, so I'll just post a minimal test that
fails in hopes that someone can see my mistake:
#include <iostream>
#include <list>
#include
Kris Braun
Hello,
I've spent the day trying to get my iterators working after upgrading to 1.31.0. I'm almost there, but I can't seem to get const and non-const versions to compare with each other. I've tried about everything I can think of, so I'll just post a minimal test that fails in hopes that someone can see my mistake:
#include <iostream> #include <list> #include
template< class Type > struct do_nothing { typedef Type result_type;
result_type operator( )( const Type& t ) { return t; } };
template< class Iterator > class simple_iterator : public boost::transform_iterator< do_nothing< typename Iterator::value_type >, Iterator > {
You cannot expect to derive an iterator from transform_iterator. The library's generated operator!= is templated, and will only work for two transform_iterators, not derived classes (not to mention other problems with that approach). 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; }; simple_iterator<whatever>::type is now the iterator you wanted. HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams
-
Kris Braun