January 2018
Intermediate to advanced
374 pages
9h 53m
English
The decltype keyword is used to retrieve the type of a variable and is used when an explicit type name is not available.
Sometimes, an explicit type name is not available, only the variable name is available. For example, polymorphic lambda functions (lambdas with auto as a parameter) do not name the type (as opposed to templated functions, where the type name has its own parameter):
|
Regular template function |
Lambda function |
|
Here, the type of v is visible as T: template <typename T>
auto square_func(const T& v){
return v * v;
} |
Here, the type of v is not visible, as it is only denoted as auto: auto square_func_lbd=[](auto v){
return v * v;
}; |
Take the previous sign function; if ...