Boost logo

Boost Users :

Subject: Re: [Boost-users] problems with C++ integer types
From: Richard Damon (Richard_at_[hidden])
Date: 2012-01-31 17:13:22


On 1/31/12 4:09 PM, Robert Ramey wrote:
> Steven Watanabe wrote:
>> AMDG
>>
>> 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, 17.4.3.1:
>> "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?
>
>> unless
>> the declaration depends on a user-defined name of external
>> linkage
> I can't see how this is related to anything. Why should I not
> be able to define a specialization locally in one file?
This provides the exception to undefined behavior above. Note that this
says that the TEMPLATE ARGUMENT must have external linkage, not that the
specialization needs to be seen globally. Note though, by the One
Definition Rule, if another files defines a specialization for the same
template arguments, the definition must be identical.

>> and unless the specialization meets the standard
>> library requirements for the original template."
> As far as I can tell. numeric_limits<T> specifies no requirements
> on T other than if numeric_limits is specialized for T should also
> be specialized for cv variations on T. OK that I get.

It defines a list of members to be defined, and the type of those
members. Your specialization needs to define these same members, and
they need to have the specified type. Also, for numeric_limits<T> any
specialization needs to have a member "static const bool is_specialize =
true;"
> No one should feel obligated to answer these questions for
> reasons other than pure enjoyment. I'm not hung up on them.
>
>> In Christ,
>> Steven Watanabe
>

-- 
Richard Damon

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