Opened 15 years ago
Last modified 10 years ago
#1020 new Patches
Boost.Iterator proposal to add is_constant_iterator
Reported by: | 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)
Change History (4)
by , 15 years ago
Attachment: | IsConstIterator.zip added |
---|
comment:1 by , 15 years ago
Owner: | set to |
---|
comment:2 by , 14 years ago
Owner: | changed from | to
---|
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 , 10 years ago
Owner: | changed from | to
---|
Implementation, tests and documentation patches of the proposal