Subject: Re: [Boost-bugs] [Boost C++ Libraries] #8011: iterator_range::size() is not SFINAE-friendly
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-02-13 01:06:04
#8011: iterator_range::size() is not SFINAE-friendly
---------------------------------------------------------+------------------
Reporter: Jonathan Wakely <jwakely.boost@â¦> | Owner: neilgroves
Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: range
Version: Boost 1.52.0 | Severity: Problem
Resolution: | Keywords:
---------------------------------------------------------+------------------
Comment (by nathanridge):
Replying to [comment:4 jwakely.boost@â¦]:
> I use `boost::zip_iterator`so to construct an end iterator that is
reachable from {r1.begin(), r2.begin(), ...} it needs to be
{r1.begin()+N, r2.begin()+N, ...} (where N is the size of the smallest
range) not {r1.end(), r2.end(), ...} because `operator==` for
`zip_iterator` is only true if all members of the tuple are equal.
>
> https://gitorious.org/redistd/redistd/blobs/master/include/redi/zip.h
> Since I switched from using the size() member it needs fixing to avoid
calling both `std::distance()` and `std::advance()`, but the point of this
ticket is that I'd prefer to use size() when possible
Let me suggest an alternative way of implementing such a zipped range:
- Use a custom iterator class rather than boost::zip_iterator
- Use a special marker value to represent 'end'
- In the begin iterator, store the end of each component range as well
as the current position in each
- When incrementing the begin iterator, increment each component iterator.
When any one of them compare equal to the corresponding end iterator, set
the iterator's value to the special marker value that represents 'end'
This way:
- You don't do an extra traversal of forward and bidirectional component
ranges to figure out their size
- You range is usable with single-pass component ranges
The only disadvantage I can see is the extra memory to store the component
end iterators in the zipped range's iterator.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/8011#comment:5> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:12 UTC