typename
suggest change- When followed by a qualified name,
typename
specifies that it is the name of a type. This is often required in templates, in particular, when the nested name specifier is a dependent type other than the current instantiation. In this example,std::decay<T>
depends on the template parameterT
, so in order to name the nested typetype
, we need to prefix the entire qualified name withtypename
. For more details, see Where and why do I have to put the “template” and “typename” keywords?template <class T> auto decay_copy(T&& r) -> typename std::decay<T>::type;
- Introduces a type parameter in the declaration of a template. In this context, it is interchangeable with
class
.template <typename T> const T& min(const T& x, const T& y) { return b < a ? b : a; }
typename
can also be used when declaring a template template parameter, preceding the name of the parameter, just likeclass
.template <template <class T> typename U> void f() { U<int>::do_it(); U<double>::do_it(); }
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents