
David Abrahams wrote:
Daniel Wallin <dalwan01@student.umu.se> 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