Boost logo

Boost :

Subject: Re: [boost] [iterator] Constness of counting_iterator
From: Dave Abrahams (dave_at_[hidden])
Date: 2013-02-01 12:06:58

on Fri Feb 01 2013, Claas <> wrote:

> Hi all!
> I was wondering why the dereference operator of counting_iterator<T> returns a constant reference to
> T instead of a reference to T.
> Naively I would expect counting_iterator<T>::reference to be T& and counting_iterator<const
> T>::reference to be const T&.
> I suppose however that there was good reason to implement counting_iterator the way it is
> implemented. Could anyone kindly point this reason out to me?

Counting iterators are strictly constant iterators. Writing into a
counting iterator would alter its position in the sequence. That
doesn't seem compatible with the expected behavior of iterators that
could be used by any algorithm.

Dave Abrahams
BoostPro Computing                  Software Development        Training             Clang/LLVM/EDG Compilers  C++  Boost

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