C++ Logo

std-proposals

Advanced search

Re: [std-proposals] enum with non-integral types

From: Thiago Macieira <thiago_at_[hidden]>
Date: Fri, 14 Mar 2025 14:00:27 -0700
On Friday, 14 March 2025 13:31:35 Pacific Daylight Time Ryan Klaus via Std-
Proposals wrote:
> With an enumeration, the writer of the enum gets to define the exact list
> of constants that can be passed to a function accepting that enum type,
> barring explicit casts of course. There's no way for a user to expand the
> list of valid constants without doing something hacky like going to the
> header and modifying the enumeration directly.

You can always just write E(5) or E(-1), provided the underlying type can hold
that value. That means it's still just a documentation or expectation that one
shouldn't use values not in the enumeration.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering

Received on 2025-03-14 21:00:29