On Thu, 29 Mar 2012, Marc Glisse wrote:
On Wed, 28 Mar 2012, Marc Glisse wrote:
On Sun, 25 Mar 2012, Marc Glisse wrote:
- a first goal is simple functions, with a single return statement (which
may even often be the only statement).
After playing with it a bit, I am not sure how to use it in the simple
forwarding case:
T f(int);
auto g(int i){return f(i);}
If T is a reference, this does a copy.
auto&& g(int i){return f(i);}
Now if T is not a reference, this returns a reference to a destroyed
temporary.
I haven't given this idea much thought, but here goes:
The main issue seems to be that "auto&&" deduction gives a dangerous unusable
answer on a temporary. Well, let's change that to make the deduction be the
same as plain "auto" in that case (how different does that make it from
decltype?). Sure, it requires some more complicated wording. But to users, it
could actually be more intuitive as auto&& would remain a do-what-I-mean
perfect forwarder. And plain "auto" would remain compatible with lambdas.
Hmm, the fact that this doesn't fit the usual "deduce auto and collapse
references with &&" model might make it unacceptable, although it would be
more useful than rejecting (or strongly warning against) the code for
temporaries.
Oh well, the current proposal is useful as is, and there is probably room
left if we later want to add a syntax that implies decltype deduction
(decltype(auto)? decltype without parenthesis?).
--
Marc Glisse