
On Feb 11, 2006, at 8:27 AM, Arkadiy Vertleyb wrote:
Hi all.
The primary purpose of decltype, according to the decltype/auto proposal, seems to be to assist in creation forwarding functions, something like:
template<class F> decltype(F()()) forward(F f) { return f(); }
For example, if f is declared to return const rvalue:
const x f();
using the real decltype (in the future, of course) would result in:
const x forward(const x(*)()) { return f(); }
Which is, of course, what we expect in this case.
Since LVALUE_TYPEOF has a problem distinguishing const x from const x&, using it in the above case would result in:
const x& forward(const x(*)()) { ^^^^^^^ return f(); }
Now, my question is: isn't this fine? The same rule (extending the lifetime of const reference) that prevented LVALUE_TYPEOF from working correctly, seems to now ensure that it is fine to use this "incorrect" result.
I think the extended lifetime rule for temporaries would make it work ok, but the mere definition of the "forward" function above will at least trigger warnings about returning a reference to a temporary. (I'm assuming you meant "const x(*f)()" as the parameter of the forward function) Best, Jaakko