Re: enum sets

Liste des GroupesRevenir à l c 
Sujet : Re: enum sets
De : fir (at) *nospam* grunge.pl (fir)
Groupes : comp.lang.c
Date : 29. Aug 2024, 15:51:58
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <0ce67f893035672e67fa53b167e543535077df04@i2pn2.org>
References : 1 2 3
User-Agent : Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
Thiago Adams wrote:
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.
>
>
ok i guess i undestand what you talkin about
you want a list of enums say from 0 to 1703 ordinally on binary level but but you also want to compiler build a table to which group it belong
but not encode it as bits
if so if you want to repeat given emon in more groups than you need to not give it new walue instead given enum would have two walues
it can be done and gives something like more typesafety but the microdictionary is imo much more interesting idea - as those dictionary things are in a way fundamental in programming

Date Sujet#  Auteur
29 Aug 24 * enum sets29Thiago Adams
29 Aug 24 +* Re: enum sets4Keith Thompson
29 Aug 24 i+- Re: enum sets1Keith Thompson
29 Aug 24 i+- Re: enum sets1Kaz Kylheku
29 Aug 24 i`- Re: enum sets1Thiago Adams
29 Aug 24 +* Re: enum sets5David Brown
29 Aug 24 i+* Re: enum sets2Thiago Adams
29 Aug 24 ii`- Re: enum sets1Thiago Adams
29 Aug 24 i`* Re: enum sets2Blue-Maned_Hawk
29 Aug 24 i `- Re: enum sets1David Brown
29 Aug 24 +* Re: enum sets8fir
29 Aug 24 i+- Re: enum sets1fir
29 Aug 24 i+- Re: enum sets1fir
29 Aug 24 i+* Re: enum sets2fir
29 Aug 24 ii`- Re: enum sets1fir
29 Aug 24 i`* Re: enum sets3Thiago Adams
29 Aug 24 i `* Re: enum sets2fir
29 Aug 24 i  `- Re: enum sets1fir
29 Aug 24 +* Re: enum sets2Bonita Montero
29 Aug 24 i`- Re: enum sets1Thiago Adams
29 Aug 24 `* Re: enum sets9fir
29 Aug 24  +- Re: enum sets1fir
29 Aug 24  +* Re: enum sets6Thiago Adams
29 Aug 24  i`* Re: enum sets5fir
29 Aug 24  i `* Re: enum sets4fir
29 Aug 24  i  `* Re: enum sets3fir
29 Aug 24  i   `* Re: enum sets2fir
29 Aug 24  i    `- Re: enum sets1fir
29 Aug 24  `- Re: enum sets1fir

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal