C++ Logo

std-proposals

Advanced search

Re: [std-proposals] D0000R0: Extensible Scoped Enumerations (draft)

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Sat, 30 May 2026 14:27:58 +0200
That is the usage:     enumclass Color : int {     Red   = 0,     Blue  = 1,     Green = 2 }; enumclass Status : int {     Ok      = 0,     Warning = 1,     Error   = 2 }; using ColorStatus = EnumUnion<Color, Status>;       ColorStatus a = Color::Green;     ColorStatus b = Status::Warning;     static_assert(ColorStatus::first_min == 0);     static_assert(ColorStatus::first_max == 2);     static_assert(ColorStatus::second_offset == 3);     static_assert(ColorStatus::second_min == 3);     static_assert(ColorStatus::second_max == 5);     Color c = a;     Status s = b;     Status fallback_status = a; // assigning a Color to Status, currently uses 0     Color fallback_color = b; // assigning a Status to Color, currently uses 0     necessary offset between the two enums is auto-detected (reflection P2966 in C++26)   -----Ursprüngliche Nachricht----- Von:Sebastian Wittmeier <wittmeier_at_[hidden]> Gesendet:Sa 30.05.2026 14:23 Betreff:AW: [std-proposals] D0000R0: Extensible Scoped Enumerations (draft) An:std-proposals_at_[hidden]; It is possible to write a library solution for combining two enums: https://godbolt.org/z/n6336ddqj The code provides a generic EnumUnion template to offer a class standing in for either enum with implicit conversion.   (disclaimer: I specified parts of it, and let me help by LLM to fill out the rest)   -----Ursprüngliche Nachricht----- Von:Rainer Deyke via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Sa 30.05.2026 12:07 Betreff:Re: [std-proposals] D0000R0: Extensible Scoped Enumerations (draft) An:std-proposals_at_[hidden]; CC:Rainer Deyke <rainerd_at_[hidden]>; On 5/29/26 20:32, Andrey Fokin via Std-Proposals wrote: > D0000R0: Extensible Scoped Enumerations (draft) > Author: Andrey Fokin lazzyfox_at_[hidden] > Date: 2026-04-20 > > Hello all, > > I am submitting a draft proposal for review: > >      PDF: > https://github.com/lazzyfox/wg21/blob/main/docs/D0000R0-ExtensibleScopedEnumerations.pdf Enum inheritance is an obvious extension to C++.  The real question is if it's useful enough to justify adding to the language.  The lesser question is what to do about the edge cases, but most of the edge cases go away if you just stick to single inheritance. #define SOME_TEXT_HERE a, b, c #define SOME_MORE_TEXT_HERE d, e enum class x { SOME_TEXT_HERE }; enum class y { SOME_TEXT_HERE, SOME_MORE_TEXT_HERE }; enum class z : x { SOME_MORE_TEXT_HERE }; // Enum z is defined as if it were enum y, // but allow implicit conversion from x to z. The requirement that enum values not conflict is nonsensical: // This is legal right now: enum class binary_digits : std::uint8_t {   zero = 0,   nada = 0,   null = 0,   one = 1,   eins = 1, }; // This would not be, and we don't even have multiple inheritance. enum class trinary_digits : binary_digits {   three = 3,   drei = 3, }; The real edge case for multiple inheritance is this: enum class x { a = 10 }; enum class y { b = 12 }; enum class x_plus_c : x { c }; // c has a value of 11 enum class y_plus_c : y { c }; // f has a value of 13 enum class x_plus_y_plus_c : x, y { c }; // What's the value of c now? -- Rainer Deyke - rainerd_at_[hidden] -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2026-05-30 12:31:01