gaazkam - 1 month ago 8

C++ Question

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?

Answer

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-definedextended signed integer types. The standard and extended signed integer types are collectively calledsigned 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 correspondingextended unsigned integer type.... The standard and extended unsigned integer types are collectively calledunsigned integer types.

3.9.1/7:

Types

`bool`

,`char`

,`char16_t`

,`char32_t`

,`wchar_t`

, and the signed and unsigned integer types are collectively calledintegraltypes. A synonym for integral type isinteger type.

3.9.1/8:

Integralandfloatingtypes are collectively calledarithmetictypes. 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.