Opened 11 years ago

Closed 11 years ago

#6495 closed Feature Requests (invalid)

consider implementing traits for numeric types in terms of numeric_limits

Reported by: Robert Ramey Owned by: John Maddock
Milestone: To Be Determined Component: type_traits
Version: Boost 1.48.0 Severity: Problem
Keywords: is_signed, is_unsigned, is_float, is_integral Cc:

Description

The following type traits

is_signed, is_unsigned, is_float, is_integral, are currently implemented by checking against a list of numeric primitives. so far so good.

But what happens when one specializes numeric_limits for his own new wizbang numeric type like big_integer, arbitrary_length integer, modular_integer, safe_integer, safe_float, etc. etc. I ideally I would expect to see that the above type traits should "just work" but they won't under the current implementation.

Note that specializing std::numeric_limits is permited by the current standard for one's own types (though not for types in the std namespace) so this is an actual problem rather than a hypothetical one.

The would leave make_signed, make_unsigned a little bit out in the cold as they're implementation can't be done in terms of std::numeric_limits.

admittedly, is_integral might not fit here as it has a very specific meaning, but I think my concern applies to the other ones for regardless.

Robert Ramey

Change History (1)

comment:1 by John Maddock, 11 years ago

Resolution: invalid
Status: newclosed

Nope sorry, the whole raison d'etre of type traits is to inspect the properties of a *type*. is_integer etc will only ever be specialized for built-in types, because "big_integer" is *not* an integer, it's class type. This whole topic has been thrashed out several times (not least when type traits were first proposed), and isn't going to change now.

Besides you can get the information you require from numeric_limits directly:

is_integer == true

All integer types. is_bounded == true

has min and max values

is_signed == true

signed integer otherwise unsigned

is_integer == is_exact == false

floating point type

Regards, John.

Note: See TracTickets for help on using tickets.