C++ Logo


Advanced search

Re: [std-proposals] Support std::numeric_limits for enums

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Sat, 1 Oct 2022 19:53:56 -0400
On Sat, Oct 1, 2022 at 7:13 PM connor horman via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> Keep in mind also that the max value of any enumerator may not be the maximum (or minimum) value the enum takes on. For example, an enum that is already a bitfield, or a type like std::byte.

And what about enums that are treated as exactly what they are: a
value that can take on a fixed number of valid values?

That's kind of the point of this. C++ has tools for treating enums as
bitfields or for treating enums as a hack for strong typedefs as
integers. But there's no way to actually test to see if an enum
contains one of the defined values in the enumeration. Even though it
has semi-strong protections against users converting arbitrary numbers
into enums, there is no way to require it.

These tools aren't meant to be useful for every enum; just for the
ones where the user expects/requires them to take on only values
corresponding to an enumerator in the enumeration.

Received on 2022-10-01 23:55:12