Date: Mon, 10 Jul 2023 11:08:16 +0200
Hi Alex,
I think you misunderstood.
Jonathan's INT_MIN / INT_MAX do not return 1 or 16, respectively, for enums.
Quite the opposite, Jonathan pointed out that the existing values INT_MIN / INT_MAX can be stored in MyEnum, so 1 or 16 are _not_ the minimum or maximum possible value for the example.
This has often used practical applications:
MyEnum wolpertinger = eMonkey | eFish | eGoat | eFrog; // 30 > 16
e.g. if like in the example the enum values are given as power of 2 flags, which can be added/ORed.
Best,
Sebastian
-----Ursprüngliche Nachricht-----
Von:Alejandro Colomar via Std-Proposals <std-proposals_at_[hidden]>
Gesendet:Mo 10.07.2023 10:53
Betreff:Re: [std-proposals] std::enum_max and std::enum_min
An:std-proposals_at_[hidden];
CC:Alejandro Colomar <alx.mailinglists_at_[hidden]>;
Hi Jonathan!
On Mon, Jul 10, 2023, 10:03 Jonathan Wakely via Std-Proposals <std-proposals_at_[hidden] <mailto:std-proposals_at_[hidden]> > wrote:
On Mon, 10 Jul 2023, 08:15 Frederick Virchanza Gotham via Std-Proposals, <std-proposals_at_[hidden] <mailto: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] <mailto:Std-Proposals_at_[hidden]>
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
--
Std-Proposals mailing list
Std-Proposals_at_[hidden]
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2023-07-10 09:08:18