What is the difference between decltype(auto)
and decltype(returning expression)
as return type of a function (template) if expr
used with
Yet another example. In the decltype(auto)
case, lambdas are allowed. In the decltype(expr)
case, lambdas are disallowed.
That's because a) lambdas are not allowed as unevaluated operands (such as in sizeof
or decltype
) and b) the type in the decltype
and in the body of the two expressions would be different, since they are two distinct lambda expressions
// ill-formed: lambda within decltype
auto f() -> decltype([]{}) { return []{}; };
// allowed: lambda is not in decltype, and only appears once
auto f() -> decltype(auto) { return []{}; }