Boost logo

Boost Users :

Subject: Re: [Boost-users] Adding constness to an iterator
From: David Abrahams (dave_at_[hidden])
Date: 2009-01-21 04:26:22


on Wed Jan 21 2009, er <erwann.rogard-AT-gmail.com> wrote:

> Hello,
>
> I'm looking to define AddConst to be used as below:
>
> template<typename BaseIter>
> class my_iter
> : public iterator_adaptor<
> my_iter<AddConst<BaseIter>::type>,
> AddConst<BaseIter>::type>{
> //...
> };

There's always boost::add_const in the TypeTraits library, but...

>
> I guess add_const<range_iterator<X>::type> is not the same as
> range_iterator<add_const<X>::type>::type, otherwise I could just take AddConst =
> add_const.

...exactly, and that's going to be a problem for

    my_iter<AddConst<BaseIter>::type>

because AddConst<BaseIter>::type only makes BaseIter itself non-const
(e.g. can't increment) which surely isn't what you meant.
Unfortunately, in general, there's no relationship between an iterator
and an associated constant iterator. I suggest you build the constant
iterator adaptor on the mutable BaseIter type if that's what the user
hands you.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net