Boost Users :
Subject: Re: [Boost-users] problems with C++ integer types
From: Dave Abrahams (dave_at_[hidden])
Date: 2012-02-01 17:53:20
on Tue Jan 31 2012, "Robert Ramey" <ramey-AT-rrsd.com> wrote:
> Steven Watanabe wrote:
>> On 01/31/2012 09:45 AM, Robert Ramey wrote:
>>> So, I've implemented
>>> a specialization of std::numeric_limits for my special kind of
>>> integer - which is OK by me. BUT, now I wonder about the idea
>>> if placing my own code into the std namespace which I would
>>> guess might raise other issues.
> Well this is sort of interesting. So it seems that I'm off the hook
> as far as specializing numeric_limits if I follow a couple of rules.
> Now it only remains to decipher the rules.
>> C++ 2003, 22.214.171.124:
>> "A program may add template specializations for any
>> standard library template to namespace std.
> OK - got it.
>> Such a
>> specialization (complete or partial) of a standard
>> library template results in undefined behavior
> Hmmm - not getting this. How does specialization
> result in undefined behavior. The whole purpose of specialization
> is to define behavior. Does this mean to say that
> any declared specialization should be defined or what?
"Undefined behavior" is a technical term, so it has specific meaning
having nothing to do with what you mean when you say "the purpose... is
to define behavior." To boil it down to basics, the standard is saying
that on an arbitrary standard C++ implementation,
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
you've done something illegal and all bets are off.
And note, the type_traits, like is_arithmetic, are not open to extension
by users. Those traits check fundamental type properties, and the set
of arithmetic types (for example) is defined by the standard. Therefore
the "meets the standard library requirements" restriction means you your
user-defined numeric type is not an arithmetic type in the is_arithmetic
-- Dave Abrahams BoostPro Computing http://www.boostpro.com
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net