C++ Logo

std-proposals

Advanced search

Re: [std-proposals] template int types

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Wed, 11 Sep 2024 00:36:20 +0300
On 9/10/24 23:49, 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`.

This has been long available in Boost.Integer.

https://www.boost.org/doc/libs/1_86_0/libs/integer/doc/html/boost_integer/integer.html

Received on 2024-09-10 21:36:27