Boost logo

Boost :

From: Andrey Semashev (andysem_at_[hidden])
Date: 2007-05-09 13:27:31

Hello David,

Wednesday, May 9, 2007, 8:27:53 PM, you wrote:

> on Tue May 08 2007, Andrey Semashev <> wrote:

>> Hello,
>> Quite often I find myself writing an is_const_iterator trait which
>> looks like this:


>> 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,
          typename iterator_category< NodeItT >::type

Here NodeItT is an adopted container iterator (const or not). It
iterates over nodes that are not value_type. MyIterator extracts
value_types from nodes on dereferencing (this logic may be tricky).

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);

Best regards,
 Andrey                            mailto:andysem_at_[hidden]

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