Using template name without parameters

I have this 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 always thought that "using the directive" is a typedef on steroids. Why can I use " templatedclass<int>::type" without specifying a parameter again, i.e. " templatedclass<int>::type<int>"?

Isn't "type = templatedclass" just text substitution used? Did I miss something?

+4
source share
2 answers

The name of the class is "entered" into the class, this is called the name of the injected class. He looks like:

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

(But this, of course, does not compile, the class may not have a manually declared member with the same name as the class.)

( ) :

[temp.local]/1

( ) , . . --, - - - , , , , <>.

+4

using. A<T> ( using ), , A A<T>.

:

template <typename T>
struct A
{
   void foo(const A&);
};

template <typename T>
struct A
{
   void foo(const A<T>&);
};

" ".

+2

All Articles