0

Is it possible, at least theoretically, that cstdint typedefs bind to some implementation specific types std::numeric_limits is not specialized for?

According http://www.cplusplus.com/reference/limits/numeric_limits , let me quote, "[std::numeric_limits] is specialized for every fundamental arithmetic type, with its members describing the properties of type T. This template shall not be specialized for any other type."

According to http://en.cppreference.com/w/cpp/types/numeric_limits , let me quote again, "implementations may provide specializations of std::numeric_limits for implementation-specific types".

"May", cppreference says. So they don't have to.

And finally, according to http://www.cplusplus.com/reference/cstdint , the typedefs defined in the header "are typedefs of fundamental integral types or extended integral types".

So, to sum up - it seems that cstdint typedefs might bind to extended integral types (whatever they are), which are not fundamental integral types (again, whatever they are), and therefore might be incompatible with std::numeric_limits . Is this correct?

However, the documentations I linked to seem to be slightly inconsistent on one point. Isn't cplusplus.com's prohibition that std::numeric_limits must not be specialized for any non-fundamental arithmetic type in opposition of cppreference's allowance that std::numeric_limits might be specialized for implementation-specific types? Unless, of course, these implementation-specific types actually are fundamental integral types, in which case, hopefully, std::numeric_limits would have to be specialized for all cstdint typedefs.

The documentations confuse me. So I ask my question here :)

EDIT.

According to http://eel.is/c++draft/cstdint , cstdint must bind to integer types. And according to http://eel.is/c++draft/limits.numeric , "Specializations shall be provided for each arithmetic type, both floating point and integer, including bool". Is the understanding that integer type is an arithmetic type and therefore std::numeric_limits must be specialized for cstdint typedefs correct?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • Your second link (if fixed by removing the trailing `/`) also says: "The standard library types that are aliases of arithmetic types (such as `std::size_t` or `std::streamsize`) may also be examined with the `std::numeric_limits` type traits." This "may" is a permission on programs. But if one reference says it's not allowed, another reference says it's allowed, and neither of those references is the standard, then the standard needs to be consulted. :) –  Jul 20 '15 at 22:31
  • @hvd See my question edit. –  Jul 20 '15 at 22:34

1 Answers1

3

The specializations such as std::numeric_limits<std::int_fast32_t> must exist.

3.9.1/2:

There are five standard signed integer types: "signed char", "short int", "int", "long int", and "long long int". ... There may also be implementation-defined extended signed integer types. The standard and extended signed integer types are collectively called signed integer types.

3.9.1/3:

For each of the standard signed integer types, there exists a corresponding (but different) standard unsigned integer type.... Likewise, for each of the extended signed integer types there exists a corresponding extended unsigned integer type.... The standard and extended unsigned integer types are collectively called unsigned integer types.

3.9.1/7:

Types bool, char, char16_t, char32_t, wchar_t, and the signed and unsigned integer types are collectively called integral types. A synonym for integral type is integer type.

3.9.1/8:

Integral and floating types are collectively called arithmetic types. Specializations of the standard template std::numeric_limits (18.3) shall specify the maximum and minimum values of each arithmetic type for an implementation.

18.3.2.1/2:

Specializations [of numeric_limits] shall be provided for each arithmetic type, both floating point and integer, including bool.

18.4.1:

namespace std {
  typedef signed_integer_type int8_t;    // optional
  //...
  typedef unsigned_integer_type uint8_t; // optional
  //...
}

So the types defined in <cstdint> might be extended types, but are definitely integer types and therefore must have corresponding specializations of std::numeric_limits.

Also, all integral types are "fundamental" in the sense used in the Standard (3.9), though not all are standard types.

aschepler
  • 70,891
  • 9
  • 107
  • 161