C++ Logo

std-proposals

Advanced search

Re: [std-proposals] template int types

From: Tom Honermann <tom_at_[hidden]>
Date: Tue, 10 Sep 2024 17:25:02 -0400
Are you familiar with the _BitInt type that was added to C23? If not,
see WG14 N2763 (Adding a Fundamental Type for N-bit integers)
<https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2763.pdf>.

Tom.

On 9/10/24 4:49 PM, Robin Savonen Söderholm via Std-Proposals wrote:
> I would find something along the lines of the following:
> ```c++
> template <size_t BITS>
> using int_bits_t = /*specific int types that exactly BITS number of
> bits*/;
> template <size_t BITS>
> using int_least_t = /*the smallest integer type holding at least BITS
> number of bits*/;
> template <size_t BITS>
> using int_fast_t = /*implementation defined but has at least BITS
> number of bits, similar approach as the regular std::int_fastN_t;
> // and same for uint...
> ```
> . I see reason for this both when defining serializable interfaces and
> when working with arithmetic where it could be useful to find an
> integer that is at least twice as big as some input. I made my own
> version of these but it was a bit cumbersome (especially dealing with
> `std::int_max_t` that may or may not be the same as `long long`.
>
> // Robin
>

Received on 2024-09-10 21:25:06