From: Arno Schödl (aschoedl_at_[hidden])
Date: 2008-08-29 10:12:13
Indeed, as long as the range does not escape, everything is fine. But here we are in trouble:
some_stacked_adaptor_range<...> rng( make_difference_range( vecnA, vecnB ) );
Again, notation makes no difference, but Neil's idea, which I fully endorse, namely easy stacking, makes the problem all the more apparent:
some_stacked_adaptor_range<...> rng( vecnA | difference( vecnB ) ); // wrong
What makes this really annoying is that there is an easy way out: Wouldn't it be more natural to represent a forward range as a single iterator, with an extra .at_end() check? This would eliminate the problem, because a difference_range would only need two such iterators, not four. Stacking them naively would have 2^N storage growth, rather than 4^N, and we still don't need to worry about range lifetime.
For other classes of iterators, the situation is similar. bidirectional ranges have at_end() and at_begin(), and random_access_ranges a size() and an operator.
I know that overthrowing such an established concept as ranges is not terribly popular, but I don't see any other way to combine easy stacking with no worry about lifetimes.
From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]] On Behalf Of Giovanni Piero Deretta
Sent: Friday, August 29, 2008 3:28 PM
Subject: Re: [boost] lifetime of ranges vs. iterators
On Fri, Aug 29, 2008 at 3:13 PM, Arno Schödl <aschoedl_at_[hidden]> wrote:
> I have seen your | operator. It is o.k. for unary things, like rng | filter( predicate ), but for binary things, it is a bit weird:
> rngA | difference(rngB)
> I find the alternatives clearer: rngA - rngB would be nice (but requires concept checking), or difference( rngA, rngB ).
What about Infix a-la FC++?
(rngA ^difference^ rngB)
I love the syntax, but maybe this is too much operator abuse.
> But regardless of notation, doesn't this suffer from the same problem that these
> objects are temporaries?
I'm still missing something: where is the problem in:
DoSomethingWithRangeThatStoresIterators( difference_range< int, int >
diffrng( vecnA, vecnB ) );
This works, as long as the range doesn't escape from DSWRTSI, or a copy is made.
[of course a make_difference_range would make the code much cleaner]
-- gpd _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost -- Dr. Arno Schoedl · aschoedl_at_[hidden] Technical Director think-cell Software GmbH · Invalidenstr. 34 · 10115 Berlin, Germany http://www.think-cell.com · phone +49-30-666473-10 · toll-free (US) +1-800-891-8091 Directors: Dr. Markus Hannebauer, Dr. Arno Schoedl · Amtsgericht Charlottenburg, HRB 85229
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk