Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does integer-class type mean in C++ since integer is a built in type

Tags:

c++

types

c++20

While reading through the documentation of std::numeric_limits I came across the following statement:

Specializations for all integer-class types are also provided. (since C++20)

My question is that what do we mean by integer class types in the above statement. I mean, I know that int is a built in type in C++. And we can provide user-defined class in C++. But I never read about an integer-class type. I tried searching that phrase on google, but didn't find anything related to this.

like image 780
Anoop Rana Avatar asked Nov 21 '25 00:11

Anoop Rana


2 Answers

From the history we can see that this pertains to the iterator concepts added in C++20; in particular, [iterator.concept.winc]/2 says

A type I is an integer-class type if it is in a set of implementation-defined types that behave as integer types do, as defined below.

[Note 1: An integer-class type is not necessarily a class type. — end note]

The library is given permission to use one of these suitably integer-like types to represent the sizes of ranges and the distances between elements of ranges.

like image 157
Davis Herring Avatar answered Nov 23 '25 13:11

Davis Herring


It's yet another set of integer types, that are neither standard integer types nor extended integer types.

There are five standard signed integer types: “signed char”, “short int”, “int”, “long int”, and “long long int”. In this list, each type provides at least as much storage as those preceding it in the list. There may also be implementation-defined extended signed integer types. The standard and extended signed integer types are collectively called signed integer types.

A problem here is that the typedef intmax_t must be defined as the largest of these integer types (thus its name :-).

Now if an implementation were to define a new set of "integer-class types" that are not "standard" or "extended" integers, but merely "integer-like", it could use those types without changing intmax_t.

Saves us from an ABI break for all previous uses of intmax_t parameters.

like image 30
BoP Avatar answered Nov 23 '25 15:11

BoP



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!