|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2005-05-09 08:25:49
Daniel Wallin <dalwan01_at_[hidden]> writes:
> David Abrahams wrote:
> [...]
>> The question is, what should we do about this? It turns out to be
>> surprisingly hard to write the declarations of these temporary
>> variables so they work in all cases. For example, v had to be a
>> const& because in one case index_result<...>::type turned out to be
>>
>> char const[4]
>>
>> and when the default is used, it's
>>
>> double
>>
>> with p[value || ...] returning a double rvalue (by value).
>>
>> Thoughts?
>
> Make the user add reference to the Default type instead of
> index_result<>::type?
I don't fully understand what you're proposing or what it's supposed
to address, but I think you might be missing the point. To make it
safe to use, ideally
index_result<...>::type whatever = p[x | some-expression];
would always cause a by-value return from p[...] when some-expression
is an rvalue.
By the same token,
f( p[x | some-expression] )
should always return by-reference from p[...], for efficiency.
This has a little less to do with how the user declares
index_result<...>::type than with the result of indexing.
-- 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