c++ - Why aren't template specializations allowed to be in different namespaces? -


Please see what I'm trying to do:

  #include & lt ; Iostream & gt; First name template {lt; Class T & gt; Class Myclass {t t; Public: Zero who_are_you () const {std :: cout & lt; & Lt; "First :: MyClass"; }}; } Namespace second {use first: myclass; Template & lt; & Gt; Square myclass & lt; Int & gt; {Int i, j; Public: Zero who_are_you () const {std :: cout & lt; & Lt; "Second: MyClass"; }}; }  

This permission is not allowed, can you please explain why why can not be an expert in different namespaces, and what are available solutions? Also, what's certain in C ++ 0x?

This will allow me for an example, for example std :: max , std :: swap , std :: numeric_limits , etc. :: std :: ? Adding something to


without supporting the undefined behavior @ AndreyT here's how I will use it:

  // my_integer is a class std :: numeric_limits & lt; My_integer & gt; :: max ();  

Can this be done?

>

C ++ 2003, §17.4.3.1 / 1: "a program can add any template specializations of standard library template for stand enrollment. depending on a standard library templates such specialization (full or partial) undefined is not an announcement to treat external linkage of user-defined name And as long as the standard standards for standard standards "

In this way, keep your expertise in a library template, and namespace std , unless it is a user defined Depends on the type and meets the requirements of the original template.

The code edited by you is considered a specialist for a user-defined name (possibly:), there is an external connection, so you should not have any problem with that thing.

It is only necessary that your expertise meets the requirements of the original template. For the sake of your type, most of them probably will put limitations on the slightest. The only part I can see is that it can not be clear that you think you have to provide expertise for the template completely, not just numeric_limits: : Max () . I.e., you have to do something (example 128-bit unsigned integer type should be in ballpark):

  namespace std {template & lt; & Gt; Class numeric_limit & lt; My_integer & gt; {Public: static const bool is_specialized = true; Stable t minute () throw () {return 0; Fixed T max () Throw () (returns / * 2 ^ 128-1 * /;} // *** Fixed const int points = 128; Static const int points 10 = 38; Constant const bool is_signed = false; static const Bool is_integer = true; constants const bool is_exact = true; static const int radix = 2; static ti ipsilon () throw () {return 0;} static t round_re () throw () {return 0;} static const int min_exponent = 0; static const int min_exponent10 = 0; static const int max_exponent = 0; static const int max_exponent10 = 0; static const bool Ha_infiniti = false; static const bool Ha_kviatt_anaan = false; static const bool Ha_ signaling_NaN = false; static const float_denorm_style h As_denorm = denorm_absent; static const bool is_name_los = false; static te infinity () throw () {return 0;} static t-silent_nn () throw () {return 0;} static t notation_nn () throw () {return 0;} Static t denorm_min () throw () {return 0;} static const bool is_iec559 = false; static const bool is_bounded = true; static const bool is_modulo = true; static constant bil net = false; Static Console Balls tinyness_before = false; Static console float_fon_style round_style = round_tovard_azero; }; }  

Some of these are actually for FP type, and it is not necessary to be meaningful for an integer type; I believe they still need to implement them.


Comments