|
Boost : |
From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2005-02-02 10:10:37
"Pavol Droba" <droba_at_[hidden]> wrote in message
| > iterator_range:
| > --------------
| >
| > value_type& front() const;
| > value_type& back() const;
| > value_type& operator[]( size_type ) const;
| > value_type& at( size_type ) const;
| >
|
| These functions seems usefull. However, I think, that operator[] should
| be available only when underlaying iterator is random-access like
yes, it won't compile otherwise.
| > void advance( size_type );
| > void narrow( size_type left, size_type right );
| > iterator_range& operator++();
| > value_type& operator*() const;
| >
|
| I assume, that these are inspired by John Torjo's RTL. I'm not very keen of
them,
| since I consider the using of an iterator_range instead of iterator
confusing.
Ok, so here's how I was thinking: if we add, let's say, only operator++() and
operator*(), then we get a very simple way to iterate over the range...
manual loops are still very inconvenient in C++.
(Yes, BOOST_FOREACH willl improve things a lot).
Anyway, currently you would have to write
for( typename range_iterator<Range>::type i = r.begin(), e = r.end(); ++i )
{ ... }
with the new stuff we simply say
for( ; r, ++r )
{ ... }
If you consider sub_range<>, then we get a new kind of "iterator" that
actually propagates constness, so it might complement iterator and
const_iterator.
| > freestanding:
| > ------------
| >
| > iterator_range make_sub_range( range&, size_type left, size_type right =
0 );
| > iterator_range make_super_range( range&, size_type left, size_type right =
| > 0 );
| > iterator_range make_range( range&, difference_type left, difference_type
right
| > = 0 );
| >
|
| Generaly the same issue as above applies. However, I find these functions
| not so offending. There might be a use for the them (last one especialy).
ok.
| What I find important when including such a functions is to make sure,
| you don't get into the problems with less capable iterators.
| (i.e that you don't disable the iterator_range for forward-only iterators
| for instance)
ah well, there is no magic in these functions, they work by calling
std::advance() and will work for all forward iterators. they will of couse not
work for single-pass iterators.
-Thorsten
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk