Recursive data structure using template won't compile
Rob T
rob at ucora.com
Thu Nov 8 10:13:29 PST 2012
I want to be clear that I'm trying to define a recursive data
structure, not a recursive D struct, which of course is not
possible.
The nodes in the d_list are allocated as pointers, and the node
size syhould be knowable during compile time, so this is IMO a
design flaw with how templates are being evaluated. It's possible
that I'm doing something wrong, so correct me if there's a
reasonable way to get this job done (eg no use of mixin hacks).
--rt
On Thursday, 8 November 2012 at 18:07:45 UTC, Rob T wrote:
> On Thursday, 8 November 2012 at 17:57:11 UTC, Philippe Sigaud
> wrote:
>> Rob, your original code:
>>
>> // d-linked list with templated payload
>> struct d_list( T )
>> {
>> struct node
>> {
>> T payload;
>> node* pred;
>> node* succ;
>> }
>> node* head;
>> node* tail;
>> }
>>
>> compiles just fine for me (Linux 32bits, DMD 2.060).
>>
>> Even with some exercising, the template doesn't fail:
>>
>> void main()
>> {
>> auto list = d_list!(int)();
>> }
>>
>>
>
> Yes that part works fine, but that's only the d_list part. When
> I try to use my supposedly re-usable d-list to define a
> recursive struct, that's when it fails. Take another look at
> the original post, you'll see what I mean.
>
> --rt
More information about the Digitalmars-d-learn
mailing list