Adding constness to an iterator
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>{ //... }; 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.
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
participants (2)
-
David Abrahams
-
er