Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2007-05-10 06:49:56


on Wed May 09 2007, Andrey Semashev <andysem-AT-mail.ru> wrote:

> Hello David,
>
> Wednesday, May 9, 2007, 8:27:53 PM, you wrote:
>
>> on Tue May 08 2007, Andrey Semashev <andysem-AT-mail.ru> wrote:
>
>>> Hello,
>>>
>>> Quite often I find myself writing an is_const_iterator trait which
>>> looks like this:
>
> [snip]
>
>>> Maybe it is worth adding to Boost.Iterators library? Or maybe there
>>> already is something like that?
>
>> What's it useful for?
>
> Mostly I used it to implement my iterators for some adopted STL-like
> containers. It shortens the iterator_facade template parameters list:
>
> template< NodeItT >
> struct MyIterator :
> public iterator_facade<
> MyIterator< NodeItT >,
> typename mpl::if_<
> is_const_iterator< NodeItT >,
> const value_type,
> value_type
> >::type,
> typename iterator_category< NodeItT >::type
> >
> {
> };

Is there some good reason you're not using iterator_adaptor here?
This looks like a classic use case for it. That would eliminate the
need for is_const_iterator in this case.

> Another use case is different iterators translation to each other. It
> came handy when I had to implement something like
> multi_index_container iterator projecting:
>
> template< int Index, typename SrcItT >
> typename mpl::if_<
> is_const_iterator< SrcItT >,
> typename nth_index< Index >::const_iterator,
> typename nth_index< Index >::iterator
> >::type project(SrcItT it);

I see. Well, I'm ambivalent. To me it doesn't look like that
particular use case is worth doing much work to extend the library
for, but if you can supply the implementation along with doc patches
and tests, I guess I would be inclined to accept them.

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
Don't Miss BoostCon 2007! ==> http://www.boostcon.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk