Methods in enums

WebFreak001 d.forum at webfreak.org
Wed Aug 16 12:22:57 UTC 2023


On Tuesday, 15 August 2023 at 10:52:00 UTC, sighoya wrote:
> First, thanks Teoh and Alexandru for presenting a possible 
> workaround
>
> However, what we also want are methods taking the enum itself 
> as argument, which isn't possible with the solutions presented 
> so far because of cyclicity.
>
> So +1 from me for a possible DIP to get it done.
>
> On Monday, 14 August 2023 at 23:40:33 UTC, WebFreak001 wrote:
>> This would allow selective imports for enums, e.g. `import 
>> somemod : MyEnum;` to also pull in all the global UFCS
>
> Can you elaborate more?
> Why are enum functions ufcs?
>
> And is it possible to import ufcs functions for a specific 
> imported symbol?
> Would interest me.

with that sentence I meant we could put the methods that used to 
be global functions that you'd usually want to call with UFCS 
into the actual symbol, so they are callable only as child 
methods. Then a selective import like `import somemod : MyEnum;` 
would have all the myEnum.xyz functions already available in 
code, while currently you would need to add `import somemod : 
MyEnum, xyz;` where `xyz` is a global method that takes a MyEnum 
as first argument


More information about the Digitalmars-d mailing list