Methods in enums
Alexandru Ermicioi
alexandru.ermicioi at gmail.com
Fri Aug 18 00:13:55 UTC 2023
On Wednesday, 16 August 2023 at 12:22:57 UTC, WebFreak001 wrote:
> ...
> 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
Then just put those methods inside struct used in enum, and
there'll be automatic import of those methods. Btw this is also
what java enum members are, i.e. plain objects of specific type
guaranteed to be only n instances during a jvm lifetime.
Best regards,
Alexandru.
More information about the Digitalmars-d
mailing list