Tuesday, May 17, 2005

Namespace templates

This might be stupid - But I was just wondering why C++ does not have namespace templates. For example I cannot do something like this...

template < typename TYPE >
namespace SOMESPACE
  static TYPE data;

Again, I cannot think of when someone would find use out of this construct. But, say a class has just static data (usually classes won't end up with only static data unless the design is flawed) then one could think of using the above construct. The data can be accessed as...

SOMESPACE< int >::data = 100;
SOMESPACE< std::string >::data = "Srinivas";

Anyway a class would become a namespace of its own name. That's why I was wondering about namespace templates. I've posted this on the comp.lang.c++ newsgroups. Just need to wait for some discussion on this. It can be found here.

No comments:

Post a Comment

What I want to say is: