Compilable Recursive Data Structure ( was: Recursive data structure using template won't compile)
Manfred Nowak
svv1999 at hotmail.com
Thu Nov 8 17:17:09 PST 2012
Nick Sabalausky wrote:
> ALL 3 types have an exact, FINITE size.
> There *IS NO RECURSION* here.
This conclusion is wrong. Otherwise one can conclude that `s' is not
recursing on itself in this code:
struct S{ S* next;}
S s;
s.next= &s;
... because `s' has a fixed and finite size.
One way to see the recursion in the problem given is to evaluate the
exact types of the three entities starting with `(d_list!R).(node!
R)'---yes, `node' is templated implicitely---and yes, not starting
names of types with upper case might confuse the senses.
Reaching `R' one might see, that
`typeof( R)'
must be equal to
`typeof( int x &( R x &( (d_list!R).(node!R))^2)^2 )'
where `T x U' is equívalent to put types `T' and `U' into a record,
`&T' is an adress of some variabkle of type `T' and
`T^2' is short hand for `T x T'.
If there is no such `R' for which this equality holds, then recursion
is not avoidable.
Please guess what I believe.
-manfred
More information about the Digitalmars-d-learn
mailing list