Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2006-03-06 20:39:43


Rene Rivera <grafik.list_at_[hidden]> writes:

> Daniel Wallin wrote:
>> I don't think the rationale for this is completely expressed in the
>> docs. The reason binding<> works like this is because of dangling
>> references to defaults. Consider from your example above:
>>
>> something_t const & q = args[something | 0];
>>
>> When binding<> returns the default type here you will get a dangling
>> reference here:
>>
>> int const& = args[something | 0]
>>
>> Our design handles this by letting binding<> return a reference type
>> when an argument is bound to the keyword, and otherwise return the
>> default type unchanged.
>
> OK I understand what you are saying, but I don't see it :-) As far as I
> understand from the docs the binding<>::type has nothing to do with the
> default value as above as it happens before one gets to extracting the
> value. I wasn't talking about changing the types that the operator[]
> return.

Consider the usage you're proposing when you /do/ want a reference to
bind to the actual argument:

  typename binding<Args,tag::k,int>::type const& x = args[k | 0]

If the "k" argument wasn't supplied, your int const& will be a
dangling reference.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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