|
Boost : |
From: Daniel Wallin (dalwan01_at_[hidden])
Date: 2005-05-09 11:59:11
David Abrahams wrote:
> 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.
It's perfectly safe for p[...] to always return by reference, even if
some-expression is an rvalue. The only problem is that it's hard for the
user to determine if the result should be held by reference or not. 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?
-- Daniel Wallin
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk