Sujet : Re: enum sets
De : thiago.adams (at) *nospam* gmail.com (Thiago Adams)
Groupes : comp.lang.cDate : 29. Aug 2024, 14:35:51
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vaptfo$3vten$1@dont-email.me>
References : 1 2
User-Agent : Mozilla Thunderbird
On 29/08/2024 10:09, fir wrote:
Thiago Adams wrote:
I am wondering how useful would be to have enum sets.
>
Let´s say you have a function that accepts only monospaced fonts.Then
you can use enum monospaced_font_type. Or a switch case where you need
to check all and only monospaced_font_type.
>
But at same type you can store at same object monospaced_font_type or
font_type.
>
enum font_type
{
enum monospaced_font_type
{
CASCADIA_FONT,
},
ARIAL_FONT
};
>
This could be arranged in any way.
>
>
reading yet once i dont know what you want
i guess you maybe say what i understand as kinda "micro dictionary"
It does not use bits. Each enumerator will have a sequential number like it is today.
When the same enumerator is used twice the number does not change.
Sample:
enum font_type
{
enum monospaced_font_type
{
CASCADIA_FONT,
},
ARIAL_FONT,
enum modern_monospaced_font_type
{
CASCADIA_FONT,
},
};
CASCADIA_FONT is 0
ARIAL_FONT is 1
The implementation could work like this:
Each enum has a set of "parent enums."
A cast or conversion from one enum to another will trigger a warning if the target type is not in the parent set.
For instance, casting from enum monospaced_font_type to enum font_type is fine because the parent set of enum monospaced_font_type is { enum font_type }.
Each enumerator will also have its own parent set, representing the enums it belongs to. For example, CASCADIA_FONT belongs to { enum monospaced_font_type, enum font_type } .
Therefore, converting an enumerator to any enum in its parent set is acceptable; otherwise, a warning will be issued.
In a switch case for an enum type, we must ensure that all enumerators of that type are present.
For example, in a switch statement for enum font_type, we need to check that all enumerators with enum font_type in their parent set are included.