Opened 21 years ago
Closed 17 years ago
#923 closed Feature Requests (Accepted)
Request extended next() for utility lib
| Reported by: | nobody | Owned by: | nobody |
|---|---|---|---|
| Milestone: | Component: | None | |
| Version: | None | Severity: | |
| Keywords: | Cc: |
Description
The standard library's "advance(it, n)" algorithm is
often awkward to use because it takes the "it" argument
by reference. At times I want to access the n-th
element in a sequence, where I don't know if the
iterator is random-access or not (e.g., a generic
algorithm where the iterator type is only required to
be a model of ForwardIterator) and the O(n) time for
advance with a non-random-access iterator is a
negligible contribution to the overall runtime of the
algorithm.
Using advance, I have to write something like this:
IteratorType it = foo.begin();
advance(it, n);
f(*it);
If the iterator type is complicated, the above is
rather awkward. I would like to instead write
f(*next(it, n));
where the overloaded next() is defined something like
this:
template <typename ForwardIterator, typename Distance>
ForwardIterator next(ForwardIterator it, Distance n)
{
advance(it, n);
return it;
}
Change History (2)
comment:2 by , 17 years ago
| Status: | assigned → closed |
|---|
Logged In: YES user_id=840777 This feature was committed to CVS on 23-Dec-2003 (boost/next_prior.hpp) and is available since Boost 1.31. Closing as accepted.
Note:
See TracTickets
for help on using tickets.
