Opened 15 years ago

Last modified 10 years ago

#1020 new Patches

Boost.Iterator proposal to add is_constant_iterator

Reported by: andysem@… Owned by: jeffrey.hellrung
Milestone: Boost 1.36.0 Component: iterator
Version: Severity: Not Applicable
Keywords: is_constant_iterator Cc:

Description

I propose to add a new trait to the Boost.Iterator library: is_constant_iterator. The trait is applied to an iterator and returns true if the iterator's reference type is a constant reference and false if the type is a non-constant reference. The trait will fail to compile when applied to iterators having non-reference reference types.

This addition would make it easier to use library components like iterator_facade and iterator_adaptor for implementing container iterator wrappers like this:

  template< NodeItT >
  struct MyIterator :
      public iterator_facade<
          MyIterator< NodeItT >,
          typename mpl::if_<
              is_constant_iterator< NodeItT >,
              const value_type,
              value_type
          >::type,
          typename iterator_category< NodeItT >::type
      >
  {
  };

Here NodeItT is a wrapped iterator and may be a const_iterator or iterator of a container.

Another use case is when a user wants to detect whether an iterator is const_iterator or iterator. An example of this: implementing functionality of iterator translation similar to Boost.MultiIndex project method.

I've attached an archive with the implementation, tests and patches to documentation. The implementation, in addition to the abovementioned functionality, supports std::vector< bool > iterators, though their reference types are not references.

Attachments (1)

IsConstIterator.zip (5.0 KB ) - added by andysem@… 15 years ago.
Implementation, tests and documentation patches of the proposal

Download all attachments as: .zip

Change History (4)

by andysem@…, 15 years ago

Attachment: IsConstIterator.zip added

Implementation, tests and documentation patches of the proposal

comment:1 by Joaquín M López Muñoz, 15 years ago

Owner: set to Dave Abrahams

comment:2 by Dave Abrahams, 14 years ago

Owner: changed from Dave Abrahams to Thomas Witt

I can't make decisions about all iterator library tickets alone, and I'm unable to form a strong opinion about this one, so assigning to my coauthor Thomas Witt.

comment:3 by Dave Abrahams, 10 years ago

Owner: changed from Thomas Witt to jeffrey.hellrung
Note: See TracTickets for help on using tickets.