|
Boost : |
Subject: Re: [boost] [range] [1.40] iterator_range::size broken for non-random access iterators
From: Ryan Gallagher (ryan.gallagher_at_[hidden])
Date: 2009-08-21 16:47:58
Eric Niebler <eric <at> boostpro.com> writes:
>
> Ryan Gallagher wrote:
> > We were just upgrading from 1.34.1 to 1.39.0 and I ran into this
> > issue which I note is still in the trunk (and I would assume the
> > 1.40 candidate).
> >
> > The definition of iterator_range::size is using operator- where
> > it should be using std::distance as it did in boost 1.34 days:
<snip>
> This change is intentional. We decided that iterator_range::size should
> be O(1), or else it shouldn't compile.
>
> To get the old behavior, you can use boost::distance in
> boost/range/distance.hpp.
>
I never call size directly though, it's just being used through sub_range<>
although I'm not sure why this method is being instantiated.
I have a multi-index index on which I call equal_range. I wrapped this result
in a sub_range<index<tag>::type> and return it. The compiler (msvc8) seems to
complain when I assign this result to a sub_range<> instance (I don't see this
calling size() though). I then pass it to BOOST_FOREACH -- perhaps this is
where size() is being called. If this is the case, then BOOST_FOREACH is broken
due to this change.
I suppose I can change to not wrap the pair of iterators in sub_range and just
pass them to BOOST_FOREACH as that's also a supported sequence type. It's just
not as nice,
-Ryan
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk