Boost logo

Boost :

Subject: Re: [boost] lifetime of ranges vs. iterators
From: Arno Schödl (aschoedl_at_[hidden])
Date: 2008-09-07 11:02:10


>> What are your referring to specificly? If you are referring to storing the
>> predicate or stride length, this is taken care of because the iterator adaptor
>> stack stores this information only once:

>I'm talking about "vertical" redundancies between layers of the stack.

Could you give a specific example?

Each bounded_iterator stores the information pertinent to its own operation (predicate, stride length, transform functor, whatever) + its base bounded iterator. The base bounded_iterator stores either two (for forward iterators: current and end) or three (for bidirectional and random_access: begin, current and end) base iterators.

The only redundancy that I still see is that you may start with a random_access iterator at the base, but somewhere in the stack the traversal category is weakened to forward. Or the user of the iterator only uses forward traversal, although the iterator type would also support bidirectional traversal. Then the base bounded_iterator stores a begin that is never used.

I am not sure this is worth optimizing for, but you could put the desired traversal category into the bounded_iterator template interface:

bounded_iterator< I, traversal_category >

bounded_iterator< char*, forward_traversal > would then be a forward bounded_iterator running on char*, of size 2x sizeof(char*). It only stores current char* and end char*, instead of begin char*, current char* and end char*.

Arno

--
Dr. Arno Schoedl · aschoedl_at_[hidden] 
Technical Director 
 
think-cell Software GmbH · Invalidenstr. 34 · 10115 Berlin, Germany 
http://www.think-cell.com · phone +49-30-666473-10 · toll-free (US) +1-800-891-8091
Directors: Dr. Markus Hannebauer, Dr. Arno Schoedl · Amtsgericht Charlottenburg, HRB 85229

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk