Compilable Recursive Data Structure ( was: Recursive data structure using template won't compile)
Manfred Nowak
svv1999 at hotmail.com
Thu Nov 8 11:12:05 PST 2012
Rob T wrote:
| struct d_list( T )
| {
| struct node
| {
| T payload;
| node* pred;
| node* succ;
| }
| node* head;
| node* tail;
| }
This doesn't loo like a list. It looks like the ancor of a list. Let
me rewrite it and use D-parlor.
| struct Ancor( T){
| struct Node
| {
| T payload;
| Node* pred;
| Node* succ;
| }
| Node* head;
| Node* tail;
| }
This might be the ancor of a doubly linked list for a `payload' of
generic type `T'. But there is a problem: generic type `T' might be
itself a double linked list using an ancor of type `Ancor'.
If this would be true and there would be no mooring everyone,
compiler included, would plunge into an infinite loop. Therefore
`T' must inform `Ancor' wether that condition comes true---or `T'
itself must take the lead.
-manfred
More information about the Digitalmars-d-learn
mailing list