Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 868483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:08:49+00:00 2026-05-15T10:08:49+00:00

Please, see what I am trying to do: #include <iostream> namespace first { template

  • 0

Please, see what I am trying to do:

#include <iostream>
namespace first
{
 template <class T>
 class myclass
 { 
  T t;
 public:
  void who_are_you() const
  { std::cout << "first::myclass"; }
 };
}
namespace second
{
 using first::myclass;
 template <>
 class myclass <int>
 {
  int i, j;
 public:
  void who_are_you() const
  { std::cout << "second::myclass"; }
 };
}

This isn’t allowed. Could you please, clarify why can’t specializations be in different namespaces, and what are the available solutions? Also, is it something fixed in C++0x?

This would allow me for example, to specialize std::max, std::swap, std::numeric_limits, etc.. without resorting to undefined behavior by adding something to ::std::?


@AndreyT Here is how I though I would use it:

// my_integer is a class
std::numeric_limits<my_integer>::max(); // specialized std::numeric_limits for my_integer

Can this be done?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:08:50+00:00Added an answer on May 15, 2026 at 10:08 am

    C++ 2003, §17.4.3.1/1: “A program may add template specializations for any standard library template to namespace std. Such a specialization (complete or partial) of a standard library template results in undefined behavior unless the declaration depends on a user-defined name of external linkage and unless the specialization meets the standard library requirements for the original template.”

    As such, you’re allowed to specialize a library template, and put your specialization in namespace std, as long as it depends on a user defined type and meets the requirements of the original template.

    The code you have in your edited question seems to be a specialization for a user-defined name that (presumably) has external linkage, so you shouldn’t have any problem with that part of things.

    That leaves only the requirement that your specialization meet the requirements of the original template. For your type, most of this will probably border on trivial. The only part I can see that might not be obvious is that you do seem to have to provide a specialization for the whole template, not just numeric_limits::max(). I.e., you’ll have to do something like (example should be in the ballpark for a 128-bit unsigned integer type):

    namespace std { 
    template <>
    class numeric_limits<my_integer> {
    public:
    
        static const bool is_specialized = true;
        static T min() throw() { return 0;
        static T max() throw() { return /* 2^128-1 */; } // ***
        static const int digits = 128;
        static const int digits10 = 38;
        static const bool is_signed = false;
        static const bool is_integer = true;
        static const bool is_exact = true;
        static const int radix = 2;
        static T epsilon() throw() { return 0; }
        static T round_error() 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 has_infinity = false;
        static const bool has_quiet_NaN = false;
        static const bool has_signaling_NaN = false;
        static const float_denorm_style has_denorm = denorm_absent;
        static const bool has_denorm_loss = false;
        static T infinity() throw() { return 0; }
        static T quiet_NaN() throw() { return 0; }
        static T signaling_NaN() 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 const bool traps = false;
        static const bool tinyness_before = false;
        static const float_round_style round_style = round_toward_zero;
    };
    }
    

    Quite a few of those are really for FP types, and aren’t required to be meaningful for an integer type; I believe they still need to be implemented.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 491k
  • Answers 491k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The two ways are equivalent, I personally prefer the second,… May 16, 2026 at 10:01 am
  • Editorial Team
    Editorial Team added an answer I believe a JSON object can be passed to a… May 16, 2026 at 10:01 am
  • Editorial Team
    Editorial Team added an answer In a hosted environment (e.g. your typical Unix / Windows… May 16, 2026 at 10:01 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

So Im trying to make an object dynamically, please see below code from my
Please review the example code below, I have a class file that is loaded
As per an assignment given to me, I am trying to see the effects
I'm getting this error (see title) while trying to parse an XML file in
So I am trying to run console 64 bit Hello World program. I have
I'm still learning C++; I was trying out how polymorphism works and I got
I have configured CodeBlocks with lib , src, bin , include paths for GTK+
Hii , I have been trying to write a program... We have a structure
I am trying to bind an observable collection to a user control but it
This has been driving me crazy for 2 days. I have been trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.