[iterator] Problems with iterator_facade and const-qualification
I'm trying to use the iterator_facade and am running into trouble. It's
not really caused by the iterator_facade, but I figured I'd ask anyway.
This takes some explanation, so if anyone reads this, know that I *do*
appreciate it. :-)
TLDR version: I'm getting a compiler error about converting between
pointers of iterator_facade<> instantiations with different const
qualifications on the value_type. The code's attached, in addition to
mostly appearing (with a few minor formatting changes) inline below.
Please help me figure out what to do to fix it.
What I'm doing is a bit roundabout, but here goes.
One fault with C++ iterators (at least from some point of view) is that
if you want to operate on different kinds of iterators you have to care
about too much -- you need to know more than just the type that op*
returns (which is all you care about most of the time, iterator_traits
notwithstanding), but what the underlying iterator type is. This means
that if you want to write code that operates on multiple kinds of
iterators, it must be a template.
Templates don't suit my needs at this time, so I'm trying to write a
couple wrapper classes that will do dynamic dispatch to different
iterator types. Think of this as writing a C++ version of Java's
Iterator interface.
Thus I define a base class for my iterators:
template
Evan Driscoll wrote:
I'm trying to use the iterator_facade and am running into trouble. It's not really caused by the iterator_facade, but I figured I'd ask anyway. This takes some explanation, so if anyone reads this, know that I *do* appreciate it. :-)
TLDR version: I'm getting a compiler error about converting between pointers of iterator_facade<> instantiations with different const qualifications on the value_type. The code's attached, in addition to mostly appearing (with a few minor formatting changes) inline below. Please help me figure out what to do to fix it.
What I'm doing is a bit roundabout, but here goes.
One fault with C++ iterators (at least from some point of view) is that if you want to operate on different kinds of iterators you have to care about too much -- you need to know more than just the type that op* returns (which is all you care about most of the time, iterator_traits notwithstanding), but what the underlying iterator type is. This means that if you want to write code that operates on multiple kinds of iterators, it must be a template.
You might google any_iterator, and see how other authors have addressed similar problems. Jeff
On 05/06/2011 11:59 AM, Jeff Flinn wrote:
You might google any_iterator, and see how other authors have addressed similar problems.
Great! I tried to find someone who had done something similar, figuring I couldn't have been the first, but all the search terms I tried were too generic. Thanks, Evan
On Fri, May 6, 2011 at 6:51 PM, Evan Driscoll
On 05/06/2011 11:59 AM, Jeff Flinn wrote:
You might google any_iterator, and see how other authors have addressed similar problems.
Great! I tried to find someone who had done something similar, figuring I couldn't have been the first, but all the search terms I tried were too generic.
Thanks, Evan
Evan, For the Boost 1.46 release I added two related features to Boost.Range. The two related features are 'any_range' and the Range Adaptor 'type_erased'. These implementations take the any_iterators that you will find commonly on the web and improve their performance by incorporating the 'small buffer optimization' which radically reduces the allocation overhead and improves the locality of data. Hence the performance overhead of this particular implementation is considerably less than others that I have tried. I strongly recommend using the any_range solution rather than redeveloping any_iterators. The relevant reference documentation: http://www.boost.org/doc/libs/1_46_1/libs/range/doc/html/range/reference/ran... http://www.boost.org/doc/libs/1_46_1/libs/range/doc/html/range/reference/ada... I hope this saves you some time. Regards, Neil Groves
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Fri, May 6, 2011 at 1:51 PM, Evan Driscoll
On 05/06/2011 11:59 AM, Jeff Flinn wrote:
You might google any_iterator, and see how other authors have addressed similar problems.
Great! I tried to find someone who had done something similar, figuring I couldn't have been the first, but all the search terms I tried were too generic.
Thanks, Evan
You can find one in the ASL that's built on iterator_facade. http://stlab.adobe.com/classadobe_1_1any__iterator.html HTH, -- Dave Abrahams BoostPro Computing http://www.boostpro.com
participants (4)
-
Dave Abrahams
-
Evan Driscoll
-
Jeff Flinn
-
Neil Groves