Meta programming: decltype


decltype evalues the return type of a function or the type of a variable and uses it further.

Trailing return types

  • This is completely a new feature for C++ developers. Till now the return value of a function should go before the function’s name. From C++11, we can also put the return type at the end of the function declaration, of course only after substituting auto for the name of the return type.
  • The primary use for decltype is declaring function templates where the function’s return type depends on its parameter types

Note that the trailing return type is no longer needed in C++14.

Decltype(auto) – type deduction

You may also like...

Leave a Reply