Talk:cpp/language/decltype

For the following function, the function body is missing:

auto add(T t, U u) -> decltype(t + u); // return type depends on template parameters

if someone tries to run the code (as is) by calling add, it will generate a compiler error.

It should have the following body: auto add(T t, U u) -> decltype(t + u) // return type depends on template parameters {  return t+u; }

Shimon0505004 (talk) 13:52, 1 June 2017 (PDT)


 * With a definition, the decltype becomes redundant since that return is deducible: it was there demonstrating the use in a declaration. But it's not technically wrong either way. --Cubbi (talk) 14:44, 1 June 2017 (PDT)

Parens and auto
Can we expand this page to clarify a few cases in particular?: BenFrantzDale (talk) 10:09, 7 September 2021 (PDT)
 * is important as it's the perfect-forwarding return type.
 * We mention it, but the distinction between  and   really isn't clear and could do with examples. It appears that if I have   then   is   and   is.
 * Even with, I believe there's a common use for  , such as   to get the plain old type of   without any const or reference qualification.