Boost logo

Boost :

From: Daniel Wallin (dalwan01_at_[hidden])
Date: 2005-05-09 18:04:27

David Abrahams wrote:
> Daniel Wallin <dalwan01_at_[hidden]> writes:
>>David Abrahams wrote:
>>I propose that the user tells index_result<> if the result of the
>>default expression should be by reference, so that:
>> index_result<.., int>::type whatever = p[x | 0];
>>whatever stores a copy of 0 in the default-case, and stores a reference
>>to p[x] otherwise.
>> int default_ = ...;
>> index_result<.., int const&>::type whatever = p[x | default_];
>>See what I'm saying now? Am I missing the point?
> That's not too bad.
> I think we might be able to make it a bit safer by detecting when the
> default is a non-const rvalue and having p[...]

Can we really detect that?

> return by value in that case. However, that might come at the cost of
> some efficiency if the user also happens to use a non-reference
> variable:
> index_result<.., heavyweight_type>::type = p[x | rvalue_expr() ]
> Of course, when it's heavy the user will probably be using || for lazy
> defaults, in which case, can we protect her?

There's only so much we can do. This case seems hard to get wrong for
the user.

Daniel Wallin

Boost list run by bdawes at, gregod at, cpdaniel at, john at