Cannot use std.array.Appender in recursive types

Nordlöw via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 9 11:25:23 PDT 2017


Why doesn't appending to `subs` work with std.array.Appender in

     struct T
     {
         string src;
         import std.array : Appender;
         Appender!(T[]) subs;
     }
     T t;
     t.subs ~= T.init; // ERRORS
     t.subs.put(T.init); // ERRORS

when it works with builtin arrays as in

     struct S
     {
         string src;
         S[] subs;
     }
     S s;
     s.subs ~= S.init;

?

Specifically

     t.subs ~= T.init

errors as

     Error: cannot append type T to type Appender!(T[])

and

     t.subs.put(T.init);

errors as

     Error: template std.array.Appender!(T[]).Appender.put cannot 
deduce function from argument types !()(T), candidates are:



More information about the Digitalmars-d-learn mailing list