Date: Mon, 10 Jul 2023 10:53:02 +0200
Hi Jonathan!
On Mon, Jul 10, 2023, 10:03 Jonathan Wakely via Std-Proposals <
std-proposals_at_[hidden]> wrote:
>
>
> On Mon, 10 Jul 2023, 08:15 Frederick Virchanza Gotham via Std-Proposals, <
> std-proposals_at_[hidden]> wrote:
>
>> Given the following enum:
>>
>> enum MyEnum : int {
>> eInvalid = 1,
>> eFrog = 2,
>> eGoat = 4,
>> eFish = 8,
>> eMonkey = 16,
>> };
>>
>> I propose that:
>>
>> std::enum_max<MyEnum>
>>
>> would evaluate to 16, and that:
>>
>> std::enum_min<MyEnum>
>>
>> would evaluate to 1.
>>
>
> Why?
>
> This is perfectly valid:
> auto e = (MyEnum)INT_MAX;
> And similarly for INT_MIN and 0 etc.
>
Heh, I learnt something new today. I didn't know about this. Would you
mind pointing to where this feature is described in the standard? I'm
curious about it.
Regarding the proposal, I find it more readable and portable, since casting
to an enum type in C doesn't do that magic. But since the feature already
exists, I wouldn't support yet another way of doing the same thing.
At the very least, I'd use this cast always within a template or macro
called to_enum<type>(value) or to_enum(type, value). But probably in a
project-defined one, and not a standard one.
Cheers,
Alex
> So you need to give some actual rationale for your proposal.
>
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
On Mon, Jul 10, 2023, 10:03 Jonathan Wakely via Std-Proposals <
std-proposals_at_[hidden]> wrote:
>
>
> On Mon, 10 Jul 2023, 08:15 Frederick Virchanza Gotham via Std-Proposals, <
> std-proposals_at_[hidden]> wrote:
>
>> Given the following enum:
>>
>> enum MyEnum : int {
>> eInvalid = 1,
>> eFrog = 2,
>> eGoat = 4,
>> eFish = 8,
>> eMonkey = 16,
>> };
>>
>> I propose that:
>>
>> std::enum_max<MyEnum>
>>
>> would evaluate to 16, and that:
>>
>> std::enum_min<MyEnum>
>>
>> would evaluate to 1.
>>
>
> Why?
>
> This is perfectly valid:
> auto e = (MyEnum)INT_MAX;
> And similarly for INT_MIN and 0 etc.
>
Heh, I learnt something new today. I didn't know about this. Would you
mind pointing to where this feature is described in the standard? I'm
curious about it.
Regarding the proposal, I find it more readable and portable, since casting
to an enum type in C doesn't do that magic. But since the feature already
exists, I wouldn't support yet another way of doing the same thing.
At the very least, I'd use this cast always within a template or macro
called to_enum<type>(value) or to_enum(type, value). But probably in a
project-defined one, and not a standard one.
Cheers,
Alex
> So you need to give some actual rationale for your proposal.
>
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2023-07-10 08:53:15