Compilable Recursive Data Structure ( was: Recursive data structure using template won't compile)

Nick Sabalausky SeeWebsiteToContactMe at semitwist.com
Fri Nov 9 20:44:38 PST 2012


On Fri, 9 Nov 2012 14:04:26 +0000 (UTC)
Manfred Nowak <svv1999 at hotmail.com> wrote:
> 
> Sorrily no one seems to have recognized this sentence in 
> digitalmars.D.learn:40918:
> 
> > Because `R' can recurse infinitely over `Ancor' a mooring and a way 
> > to that mooring is needed.
> 
> In regex-parlor this meens, that `( R!Ancor!)*' is the type the 
> compiler should be able to handle according to the template
> definitions given.
> 
> But the compiler currently can only handle types with a finite length 
> of description on instantiation. For me it is in doubt that this 
> restriction can be declared as a bug.
> 

But all of the OP's types *do* have a finite length of description.

I do understand what you are trying to doing with the mooring (although
I admit I wasn't familiar with the word "mooring" until this
discussion), and I definitely understand what that technique is used
for. But it's not relevant to the OP's example, as he's not trying to
do anything that for which that "mooring" is actually needed.

Note that the following structs do NOT require "mooring" and *already*
work perfectly fine with DMD:

struct S1 { S1* s; }

struct S2(T) { S2!(T)* s; }

Those work perfectly fine, even once you actually instantiate S2. The
OP's example follows the same pattern as those.

If, OTOH, there had been something like this:

struct S3(T) { S3!(S3)* s; }

Then *that* would require the mooring you described. But the OP was
never trying to do anything like that.



More information about the Digitalmars-d-learn mailing list