Suppose that I have a template function (e.g., foo), that returns a const dependent type. The options to qualify the return type as const is to either put const at the left of typename keyword:
template<typename T>
const typename T::bar
^^^^^
foo(T const& baz) {
...
}
or at the right of the dependent type:
template<typename T>
typename T::bar const
^^^^^
foo(T const& baz) {
...
}
But what if I put the const qualifier between the typename keyword and the dependent type?
template<typename T>
typename const T::bar
^^^^^
foo(T const& baz) {
...
}
The above as expected, fails to compile for GCC and CLANG, but to my surprise VC++ compiles it fine.
Q:
- Is this a VC++ extension?
- Does the C++ standard say anything about where is the appropriate place to put
constqualifier in such a context?
Yes.
typenameappears in a typename-specifier, whose production isIn other words, it must be followed directly by a nested-name-specifier.
constis not allowed.