C++ Logo

std-proposals

Advanced search

Re: [std-proposals] lambdas in enums

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Fri, 14 Mar 2025 10:08:29 +0100
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

Received on 2025-03-14 09:13:36