C++ Logo

std-proposals

Advanced search

Re: [std-proposals] D4037R0 Allowing signed char and unsigned char in random number generation

From: Jens Maurer <jens.maurer_at_[hidden]>
Date: Thu, 26 Feb 2026 22:28:16 +0100
On 2/26/26 17:44, Jan Schultke via Std-Proposals wrote:
> Hi,
>
> I'm working on another proposal that may likely be a "slam dunk":
> https://isocpp.org/files/papers/D4037R0.html <https://isocpp.org/files/papers/D4037R0.html>
>
> In short, this allows std::uniform_int_distribution<unsigned char> and such things, which is currently IFNDR/compile-time UB. https://cplusplus.github.io/LWG/issue2326 <https://cplusplus.github.io/LWG/issue2326> previously attempted the same, but was closed as NAD because it was considered a feature request.
>
> I'm mainly posting here to see if anyone has some historical context into why this was ever disallowed, or in case someone has a good reason not to allow it now; I don't see any good reason.

For generators, using "unsigned char" and friends seems to make zero sense,
in particular with the generators supplied in the standard. Making this
diagnosable seems to be a plus.


I can see why someone wants to have a

  std::uniform_int_distribution<unsigned char>(0, 255)

which is the same as

  std::uniform_int_distribution<unsigned int>(0, 255)

except for the difference in return type; the value range is the same.

The wording in the paper isn't sufficiently differentiating those two
cases.

Jens

Received on 2026-02-26 21:28:23