c++templatesscopedeclaration

What is a declaration outside the template-parameter-list?


In the [basic.scope.temp] section of the C++ standard, it is mentioned:

6.4.9 Template parameter scope

Each template template-parameter introduces a template parameter scope that includes the template-head of the template-parameter.

Each template-declaration D introduces a template parameter scope that extends from the beginning of its template-parameter-list to the end of the template-declaration. Any declaration outside the template-parameter-list that would inhabit that scope instead inhabits the same scope as D. The parent scope of any scope S that is not a template parameter scope is the smallest scope that contains S and is not a template parameter scope.

What does "any declaration" and "the same scope as D" mean in the second sentence of the last paragraph?

I was unable to get a more detailed explanation from the internet.

Can anyone provide such an example and explain the significance of this requirement?


Solution

  • Consider

    namespace ns {
        template<class T>
        using A = struct X;
    }
    

    Here the template parameter T inhabits the template parameter scope, while both struct X and A inhabit the scope where the template declaration inhabits, namely the scope of ns.