Why can't namespaces be template parameters?

c++, language-design, namespaces, templates

Solution

This would be:

- (IMO) Inappropriate: Namespaces avoid name clashes. Polymorphism is outside their charter.

- Unnecessary: It would achieve nothing that can't already be done with structs.

- Possibly difficult: A namespace isn't a complete, self-contained entity. Different members of a namespace can be declared in different headers and even different compilation units.

Problem

I understand that namespaces cannot be template parameters. See the question, "template specialized on a namespace": Given: ``` namespace A { class Foo; class Bar; } namespace B { class Foo; class Bar; } ``` I want to template a class on the namespace `A` or `B` such that the following works: ``` template<name> class C { name::Foo* foo; name::Bar* bar; }; ``` I was wondering why this is the case. I understand that templates aren't structures, but is there a technical limitation to the compiler's design? Or is there some significant trade off for implementing this functionality?

Original source

Related problems