Date: Tue, 28 Apr 2026 19:03:03 +0500
Thanks for your response!
The answer is yes, and it will look like this:
enum class A { voilet, blue, roses, red};
constexpr A enum_obj= A::blue;
Enum_wrapper B{enum_obj};
enum class enum_2 { voilet, blue, roses, red};
enum_2 enum_obj_2= enum_2 ::blue ;
Enum_wrapper <enum_2, Enum_wrapper <A>> second_wrapper{ enum_obj_2
};
When the code is finished, then the object "second_wrapper" could be
assigned enum_obj as well, and when accessed in a context requiring
an enum, then the object will return enum_obj as an Enum_wrapper <A>.
That is the main goal of the whole thing. Any access requiring runtime
tracking would still rely on std::variant and in fact I would try to write
code that sees if any non-constival operation call happened in which
case, the fall back is to use an variant stored in the object. The compiler
can ofcourse optimize such a variant away if it is unused (in case the
usage of the enum was all with other constexpr enums). To make sure that I
can track an non constval call, I can instantiate a dummy object(such that
their destructor is also instantiated (by a call)) in the call of any non
consteval call using dummy template arguments, and when a consteval
operation will only be chosen if the instantiation of that object does not
exist (using a dummy template argument with a default value that checks if
the specialization has a destructor that exists) before every check to see
if a non consteval operation. My code already demonstrates some of how it
is done.
On Tue, Apr 28, 2026 at 6:42 PM Sebastian Wittmeier via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> Hi Muneem,
>
> the use of your current code (what you linked) is
>
> enum class A { voilet, blue, roses, red};
> constexpr A enum_obj= A::blue;
> Enum_wrapper B{enum_obj};
> Enum_wrapper_complete wrap{B};
>
> Can B define additional values for the enum class A? E.g. any of { yellow,
> white, green } in addition to the ones for A?
>
> I think that is the main reason for inheritance of enum classes to extend
> the possible values.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
The answer is yes, and it will look like this:
enum class A { voilet, blue, roses, red};
constexpr A enum_obj= A::blue;
Enum_wrapper B{enum_obj};
enum class enum_2 { voilet, blue, roses, red};
enum_2 enum_obj_2= enum_2 ::blue ;
Enum_wrapper <enum_2, Enum_wrapper <A>> second_wrapper{ enum_obj_2
};
When the code is finished, then the object "second_wrapper" could be
assigned enum_obj as well, and when accessed in a context requiring
an enum, then the object will return enum_obj as an Enum_wrapper <A>.
That is the main goal of the whole thing. Any access requiring runtime
tracking would still rely on std::variant and in fact I would try to write
code that sees if any non-constival operation call happened in which
case, the fall back is to use an variant stored in the object. The compiler
can ofcourse optimize such a variant away if it is unused (in case the
usage of the enum was all with other constexpr enums). To make sure that I
can track an non constval call, I can instantiate a dummy object(such that
their destructor is also instantiated (by a call)) in the call of any non
consteval call using dummy template arguments, and when a consteval
operation will only be chosen if the instantiation of that object does not
exist (using a dummy template argument with a default value that checks if
the specialization has a destructor that exists) before every check to see
if a non consteval operation. My code already demonstrates some of how it
is done.
On Tue, Apr 28, 2026 at 6:42 PM Sebastian Wittmeier via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> Hi Muneem,
>
> the use of your current code (what you linked) is
>
> enum class A { voilet, blue, roses, red};
> constexpr A enum_obj= A::blue;
> Enum_wrapper B{enum_obj};
> Enum_wrapper_complete wrap{B};
>
> Can B define additional values for the enum class A? E.g. any of { yellow,
> white, green } in addition to the ones for A?
>
> I think that is the main reason for inheritance of enum classes to extend
> the possible values.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2026-04-28 14:03:26
