Boost logo

Boost :

From: Andrey Semashev (andysem_at_[hidden])
Date: 2007-05-11 17:34:42


Hello David,

Thursday, May 10, 2007, 2:49:56 PM, you wrote:

> 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.

Well... I guess I could use iterator_adaptor in some cases and I can't
remember why I didn't in other. Thanks for the pointer.

>> 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.

I agree that the case is rather specific, though I think such template
could still be handy here and there. Since I don't have any striking
examples of use right now and a little bit short in time, I'll leave
it to some day when I have either of them. :)

-- 
Best regards,
 Andrey                            mailto:andysem_at_[hidden]

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