[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Leaving namespace for template specializations

Knut Stolze

10/14/2008 9:38:00 PM

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).

--
Knut Stolze

1 Answer

Ian Collins

10/14/2008 9:52:00 PM

0

Knut Stolze wrote:
> 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.

--
Ian Collins