Boost logo

Boost :

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


> void incement() { //similar thing for decrement
> offset += N;
> }

> void advance(distance_type n) {
> offset += n * N;
> }

> reference dereference() const {
> return base[offset];
> }

> distance_type distance_to(filter_iterator rhs) {
> return ((base - rhs.base) + (offset - rhs.offset)) / N ; // I
might have got the sign wrong
> }

In the case of a base forward_iterator, we can do without any space overhead with the same trick used for the filter_iterator. We implement a strided_range and then derive the strided_iterator from it. The strided_range stores its underlying random_access range, and adapted_range interface::increment/advance can check the underlying range for empty. It would be like:

increment() {
   for( difference_type i=0; i<N && !base.empty(); ++i ) {
      base.increment(); // the adapted_range::increment which increments begin, base is a range
   }
}

--
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