C++ Logo

std-proposals

Advanced search

Re: [std-proposals] lambdas in enums

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Fri, 14 Mar 2025 10:34:09 +0100
Can an enum contain   {0,0.f} and alternatively {0,1.f} or must each component be unique?   It would store both formats in memory? So the size would be 8 bytes?   Or is the value stored with the first component and the others are converted by the compiler? -----Ursprüngliche Nachricht----- Von:Filip <fph2137_at_[hidden]> Gesendet:Fr 14.03.2025 10:27 Betreff:Re: [std-proposals] lambdas in enums An:std-proposals_at_[hidden]; CC:Sebastian Wittmeier <wittmeier_at_[hidden]>; std-proposals_at_[hidden]; It seems like a sensible way to write the types in this inheritance style. You do not need to list every type, I just added … to show that it should go automatically and to avoid problems with objects that can be constructed from other types. int can be converted to float so it would be problematic to have both of them in an enum.  Why should it be a problem to have an enumeration of any object? Fundamentally enum lists values known at compile time and supports ++ on the previous value. Holding multiple values with different syntax is just easier and nicer syntax.  It would not break any use cases of current enum, functions inside of it would be available only after ; and inside enum struct|class Cheers, Filip Wiadomość napisana przez Sebastian Wittmeier via Std-Proposals <std-proposals_at_[hidden]> w dniu 14 mar 2025, o godz. 10:13:  Why would you inherit from multiple types?   This seems to be better served with functions and arrays?   enums are constants from a limited set.   And each time you specify one, you would have to give the values of each inherited type?   Constants with several components could be sometimes used as bit fields in embedded programming.   You could also specify n-dimensional coordinates. But would you use an enum for 3D coordinates?   -----Ursprüngliche Nachricht----- Von:Filip via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Fr 14.03.2025 10:00 Betreff:Re: [std-proposals] lambdas in enums An:std-proposals_at_[hidden]; CC:Filip <fph2137_at_[hidden]>; Tom Honermann <tom_at_[hidden]>; std-proposals_at_[hidden]; I agree with @Marcin_Jaczewski  The most useful would be to have ‘;’ after the last enum member would solve this issue. Maybe we could add some extra values here: ‘’’enum struct E : int, float { A { 0, 0.5f }, B { 3, 0.42f }, C { …, 0.0f } ; // end of enumeration @Marcin int foo() // would act like a namespaced function // getting values operator int() … operator float() … }; ‘’’ Instead of ‘=‘ we could use an initializer list and list values of the “inherited” types on top. Each type would then need to have constexpr constructor and ++ operator if the types are not listed explicitly. “…” would indicate that it should just follow incremental values. Cheers, Filip Wiadomość napisana przez Marcin Jaczewski via Std-Proposals <std-proposals_at_[hidden]> w dniu 12 mar 2025, o godz. 23:56: ``` enum class E {   A = 1, B = getSometing(), C = 3   , // last comma to still allow standard formatting of `,` after each value   ; // <- here! end of values   //now parsing is similar to `class`, you can't declare new values of enum.   bool foo();   E getSometing(); }; ``` -- Std-Proposals mailing list 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 2025-03-14 09:39:17