Mutually recursive template expansion

Imperatorn johan_forsberg_86 at hotmail.com
Sat Oct 2 10:07:27 UTC 2021


On Friday, 1 October 2021 at 14:03:06 UTC, Stephen wrote:
> I've been trying out templates in more depth and one thing I 
> was wondering was whether template expansions with circular 
> dependencies might work.
> Here is an example that doesn't work:
> ```d
> mixin(A!());
> mixin(B!());
>
> void main() {}
>
> template A() {
>     const char[] A = q{
>         struct Ar {
>             Br b;
>         }
>     };
> }
>
> template B() {
>     const char[] B = q{
>         struct Br {
>             Ar a;
>         }
>     };
> }
> ```
> This code should work should mutual recursion be supported. How 
> might I get it to work properly (without sacrificing recursion 
> or templates)?

Just curious since I haven't found a use case for this myself, 
what's the benefit rather than having a separate struct?


More information about the Digitalmars-d-learn mailing list