Boost logo

Boost :

Subject: Re: [boost] [iterator] counting_iterator::reference should bevalue_type?
From: David Abrahams (dave_at_[hidden])
Date: 2009-01-06 10:08:27

on Mon Jan 05 2009, Arno Schödl <> wrote:

>>> currently, counting_iterator<T>::reference is Incrementable const&. This makes
>>> reverse_iterator< counting_iterator<T> >::dereference return a reference to a
>>> temporary variable:
>>> typename super_t::reference dereference() const { return
> *boost::prior(this->base());
>>> }
>>> IMO, the solution is to make counting_iterator return by value.
>>But then it is no longer a C++03 random access iterator.
> The same is true for a random_access_traversal transform_iterator with a functor
> returning by value. Why is this so bad?

It's not "so bad," it's just an unnecessary limitation. If you really
need a random access counting iterator, you'd be out of luck.

Dave Abrahams
BoostPro Computing

Boost list run by bdawes at, gregod at, cpdaniel at, john at