Wrapper around a recursive data type

Steven Schveighoffer schveiguy at gmail.com
Tue Jul 9 03:54:53 UTC 2024


On Monday, 8 July 2024 at 08:56:51 UTC, drug007 wrote:
> How can I "break" this recursion or some other work around to 
> fix it?

A few ideas:

1. If it's immediately recursive (that is, contains a pointer to 
itself), just use the type itself somehow. You may not be able to 
do this with recursive templates.
2. If the data itself is static, and not actually containing 
different things, defer the construction of the Meta members 
until needed. In other words, make them structs with a member 
which accesses the meta when requested.
3. In a project I have which constructs a parallel type on 
existing types, I use `opDispatch` to defer instantiation of the 
members until later. This may or may not work for you depending 
on the use case (you can't introspect `opDispatch`).

-Steve


More information about the Digitalmars-d-learn mailing list