Using RefCounted in recursive structures and templates

Lodovico Giaretta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue May 10 12:43:25 PDT 2016


Hi,

I'm trying to use std.typecons.RefCounted on recursive structures 
to emulate garbage-collected classes, but it doesn't work, 
because the RefCounted implementation ends up creating a cycle in 
the structure hierarchy.

import std.typecons: RefCounted;

struct S
{
     RefCounted!S s; // error: struct S no size yet for forward 
reference
}

Even worst when I try to mix this with templates:

alias Node(T) = RefCounted!(_Node!T);
struct _Node(T)
{
     Node!T parent; // error: recursive template expansion
}

Is there some way to bypass these limitations, and use refcounted 
structures like classes?

Thank you in advance.


More information about the Digitalmars-d-learn mailing list