The decltype specifier
This specifier, introduced in C++11, returns the type of an expression. It is usually used in templates together with the auto
specifier. Together, they can be used to declare the return type of a function template that depends on its template arguments, or the return type of a function that wraps another function and returns the result from executing the wrapped function.
The decltype
specifier is not restricted for use in template code. It can be used with different expressions, and it yields different results based on the expression. The rules are as follows:
- If the expression is an identifier or a class member access, then the result is the type of the entity that is named by the expression. If the entity does not exist, or it is a function that has an overload set (more than one function with the same name exists), then the compiler will generate an error.
- If the expression is a function call or an overloaded operator function, then the result...