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

Rob T rob at ucora.com
Thu Nov 8 13:46:46 PST 2012


On Thursday, 8 November 2012 at 21:15:17 UTC, Manfred Nowak wrote:
> Rob T wrote:
>
>> In fact, I can define the structure just fine provided that I 
>> do not use a template.
>
> .. and if one uses a template one can get an infinite recursion,
> because templates include recursion. This is the case in your 
> code.
>
> The code I gave elimates that infinite recursion. The code 
> compiles
> although it uses a template.
>
> Not seeing e recursion does not mean that there is none. Not 
> every
> recursion is as simple to see as:
>
> | alias X Y;
> | alias Y X;
>
> -manfred

I think I'm starting to understand what you are doing, however 
we're operating on two separate planes of existence.

What you are describing, is a different structure than what I 
want. The template creates two separate struct types for R, one 
with a list and one without (R1 & R2), but I want only one type 
R, otherwise it will introduce a ton of complications in the form 
of me having to make just about eveything that uses these two 
different structures a template and/or duplicated overloaded 
functions.

Perhaps I just don't understand the in's and out's of D 
templates, but it's just not doing what I want.

So is there a way to retain identical struct types for R by 
disabling the not-so-useful-in-my-case template recursion?

--rt



More information about the Digitalmars-d-learn mailing list