Leaving namespace for template specializations

K

Knut Stolze

Hi,

Let's assume I have a namespace that contains a class definition. Now I would like to add a template specialization for std::numeric_limits for the new class. I want to have this specialization inside the scope of the namespace. Is there any way how I can "leave" or "unnest" the namespace NS so that I can have the declaration inside the "std" namespace instead of NS::std.

#include <iostream>
#include <limits>

namespace NS {

class ID {
public:
ID() : mValue(0) { }
ID(int value) : mValue(value) { }

private:
int mValue;
};

// this is what should be in ::std but not in NS::std
// namespace std {
// template<>
// struct numeric_limits<NS::ID> : public numeric_limits<int> { };
// }

}

Is there a way to achieve this?

For background information: the class is actually defined via a macro. I am using this to have different types of IDs that cannot be compared/assigned with each other (which would be possible with a regular typedef).
 
I

Ian Collins

Knut said:
Hi,

Let's assume I have a namespace that contains a class definition. Now I would like to add a template specialization for std::numeric_limits for the new class. I want to have this specialization inside the scope of the namespace. Is there any way how I can "leave" or "unnest" the namespace NS so that I can have the declaration inside the "std" namespace instead of NS::std.
No, the specialisations must be in the namespace std.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top