473,320 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Leaving namespace for template specializations

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

Oct 14 '08 #1
1 1988
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
Oct 14 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: nikola | last post by:
Hi all, I was working with a simple function template to find the min of two values. But since I would like the two values to be different (type) I dont know what kind of value (type) it will...
1
by: Imre | last post by:
Let's suppose we have a primary template with one argument defined in a header file. Two source files include this header, and both define a specialization of the primary template. Later, both...
1
by: Samee Zahur | last post by:
Why aren't we allowed to do partial specializations like these on numeric template parameters? That would have allowed us to do all kinds of interesting stuffs like loops of variable nesting (bad...
7
by: Kai-Uwe Bux | last post by:
Hi folks, I observed something that puzzles me. When I do namespace xxx { using std::swap; } it appears that xxx::swap and std::swap are not strictly equivalent. In particular, I think...
4
by: Alfonso Morra | last post by:
Does VC 7.1 support template specialization and partial specialization ?
11
by: Noah Roberts | last post by:
template < typename T > std::istream & operator >(std::istream & in, std::pair<T,T& p) { in >p.first >p.second; return in; } .... std::istream_iterator< std::pair<size_type, size_type
16
by: Hendrik Schober | last post by:
Hi, suppose we have template< typename T > struct X; and some specializations: template<>
1
by: jason.cipriani | last post by:
Here is an example with 3 files, containing a template structure and also a template function. The header A.h declares a template structure A with a default (i.e. for any template parameter),...
5
by: (2b|!2b)==? | last post by:
I would like to know if I can specialize only a specific method for a class template. Is the (specialization) code below valid? template <typename T1, typename T2> class MyClass { public:
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.