29 Aug 16:12
Re: lifetime of ranges vs. iterators
Arno Schödl <aschoedl <at> think-cell.com>
2008-08-29 14:12:13 GMT
2008-08-29 14:12:13 GMT
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. Arno -----Original Message----- From: boost-bounces <at> lists.boost.org [mailto:boost-bounces <at> lists.boost.org] On Behalf Of Giovanni Piero Deretta Sent: Friday, August 29, 2008 3:28 PM To: boost <at> lists.boost.org Subject: Re: [boost] lifetime of ranges vs. iterators On Fri, Aug 29, 2008 at 3:13 PM, Arno Schödl <aschoedl <at> think-cell.com> 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: vector<int> vecnA; vector<int> vecnB; 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> think-cell.com 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 _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
RSS Feed