
On 07.03.2011 13:44, Joel Falcou wrote:
Now, my guess is that const ref lifespan propagation still apply in 0x, so doing somethign along:
auto f( X const& x) -> decltype(x+x*declval<X const>()) { X const local; auto that = x + x*local; return that; }
will surely works (more or less, untested code).
Nope, won't work. Lifespan extension extends the life of temporary objects to the life of the concrete reference they're bound to. 'local' is not a temporary, and the concrete reference it is bound to is the argument of the * operator in x*local, which is gone before 'that' is even initialized. The problem with the whole thing is that the lifetime becomes complicated, so it's very hard for a C++ programmer to see if a piece of code is correct. Sebastian