Deutsch English Français Italiano |
<0ce67f893035672e67fa53b167e543535077df04@i2pn2.org> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail From: fir <fir@grunge.pl> Newsgroups: comp.lang.c Subject: Re: enum sets Date: Thu, 29 Aug 2024 15:51:58 +0200 Organization: i2pn2 (i2pn.org) Message-ID: <0ce67f893035672e67fa53b167e543535077df04@i2pn2.org> References: <vaoclb$3lfbf$1@dont-email.me> <3be5b29ade1ce269874ab1ef8abf1bd666a7fc9c@i2pn2.org> <vaptfo$3vten$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Thu, 29 Aug 2024 13:52:00 -0000 (UTC) Injection-Info: i2pn2.org; logging-data="146296"; mail-complaints-to="usenet@i2pn2.org"; posting-account="+ydHcGjgSeBt3Wz3WTfKefUptpAWaXduqfw5xdfsuS0"; User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24 X-Spam-Checker-Version: SpamAssassin 4.0.0 In-Reply-To: <vaptfo$3vten$1@dont-email.me> Bytes: 3745 Lines: 95 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