idiomatic D: what to use instead of pointers in constructing a tree data structure?

Meta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jan 7 12:25:09 PST 2015


On Wednesday, 7 January 2015 at 16:17:47 UTC, Tobias Pankrath 
wrote:
>  A slice seems overkill to refer to just one object, but is that
>> the best way ?
>
> struct Tree
> {
>     Tree[] children;
> }
>
> Is one way to do it.

You can add some nice sugar for this as well:

struct Tree
{
     this(string data, Tree[] children...)
     {
         this.data = data;
         this.children = children;
     }

     string data;
     Tree[] children;
}

http://dpaste.dzfl.pl/76a8a4c44345


More information about the Digitalmars-d-learn mailing list