Methods in enums

Alexandru Ermicioi alexandru.ermicioi at gmail.com
Fri Aug 18 00:25:13 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.

If you need to know which member of enum that particular instance 
of a struct is, that has it's method invoked, then you could 
check for this
inside function body of said method, by looking to which enum 
member this instance is identical to by either memory address, or 
equality.

Btw there should not be any problems with self reference in case 
if you have enum type as an argument to a method inside struct 
imho.

Best regards,
Alexandru.


More information about the Digitalmars-d mailing list