Boost logo

Boost :

Subject: Re: [boost] [iterator] Is there general const_iterator adaptor?
From: Philipp Moeller (philipp.moeller_at_[hidden])
Date: 2013-04-28 09:38:01

TONGARI <tongari95_at_[hidden]> writes:

> Hi folks,
> I wonder if there's a general const_iterator adaptor that transforms any
> iterator to a const one:
> template<class Iterator>
> struct const_iterator
> : iterator_adaptor
> <
> const_iterator<Iterator>, Iterator
> , typename iterator_value<Iterator>::type const
> >
> {
> const_iterator() {}
> const_iterator(Iterator const& base)
> : const_iterator::iterator_adaptor_(base)
> {}
> };
> Which is simple but handy for use in that we don't have to make 2 versions
> for both const & non-const iterators each time we make a container.
> Does Boost offer this which I missed somewhere, or would you think it's a
> good idea to add?

If you look at the documentation of iterator_facade you will see that it
already shows how to just write one version of the iterator and get a
const version for free: pass a `const T` as the second argument of
iterator_face and it should work.


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