Recursive delegate type?

WB witold.baryluk at gmail.com
Wed Apr 23 00:35:40 UTC 2025


On Tuesday, 22 April 2025 at 20:04:52 UTC, Timon Gehr wrote:
>
> D does not support equirecursion, but there is isorecursion:
>
> ```d
> struct OpCodeHandler{
>     void function(OpCode *ops, Reg *regs, OpCodeHandler*) 
> payload;
>     alias this=payload;
> }
> ```
>
> You can also unwrap it once:
>
> ```d
> alias OpCodeHandler=void function(OpCode *ops, Reg *regs, 
> OpCodeHandlerWrapper*);
> struct OpCodeHandlerWrapper{
> 	OpCodeHandler payload;
> 	alias this=payload;
> }
> ```
>
> You may have to wrap and even unwrap manually sometimes, but 
> there are no _unsafe_ casts required, at least.

That is pretty smart. Recursion works in structs in D, and with 
alias it is almost transparent. I will try that. Code gene should 
be the same too.

Also, I never heard of the term equirecursion and isorecursion, 
but nice to know the term, so the problem is easier to google.



More information about the Digitalmars-d mailing list