c++ - Using template name without parameters -



c++ - Using template name without parameters -

i have code:

template <typename a> class templatedclass { public: using type = templatedclass; }; template <typename a> class sinkstuff { public: void print() { cout << "generic sinkstuff"; } }; template <typename a> class sinkstuff <templatedclass<a>> { public: void print() { cout << "partiallyspecialized sinkstuff"; } }; template <typename ntoa> struct pass_parameter : sinkstuff<typename templatedclass<ntoa>::type> {}; int main() { pass_parameter<int> obj; obj.print(); cout << is_same<templatedclass<int>, typename templatedclass<int>::type>::value; // 1, yes }

i thought "using directive" typedef on steroids. how come can utilize "templatedclass<int>::type" without specifying parameter again, i.e. "templatedclass<int>::type<int>" ?

isn't "using type = templatedclass" textual substitution? missing something?

the name of class "injected" class, called injected-class-name. similar to:

class my_class_name { public: typedef ::my_class_name my_class_name; };

(but of course of study doesn't compile, class may not have manually declared fellow member of same name class.)

class templates have injected-class-name, , can used refer class template itself, or current specialization (including current template arguments), depending on context:

[temp.local]/1

like normal (non-template) classes, class templates have injected-class-name. injected-class-name can used template-name or type-name. when used template-argument-list, template-argument template template-parameter, or final identifier in elaborated-type-specifier of friend class template declaration, refers class template itself. otherwise, equivalent template-name followed template-parameters of class template enclosed in <>.

c++

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -