Boost logo

Boost :

Subject: Re: [boost] [range] Question about adapted range safety given C++11 auto
From: Dave Abrahams (dave_at_[hidden])
Date: 2012-04-22 18:59:49


on Sun Apr 22 2012, Eric Niebler <eric-AT-boostpro.com> wrote:

> On 4/22/2012 6:21 AM, Beman Dawes wrote:
>> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3350.html
>> claims:
>>
>> "Boost's range library focuses on defining a set of Range concepts
>> that allow Containers to be Ranges. Because Containers are
>> heavy-weight, this forces Boost to use references for all of their
>> uses of Ranges, including Ranges that are captured by Range
>> Adapters. This worked fine in C++98, where users couldn't name the
>> types of the Range Adapters in order to declare local variables, but
>> with C++11's auto keyword, users can now save adapted ranges. Since
>> Boost's adapted ranges capture references to their arguments, which
>> can be temporaries, this is no longer a safe design."
>>
>> Is this claim correct?
>
> I imagine so. Expression template libraries (including std::valarray!)
> have the same problem.

Another way of saying it is, "no more correct than the same complaint
about any other type that captures a reference to its ctor argument
(e.g. std::ref)."

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk