On 8/9/17 2:25 PM, Nordlöw wrote:
Why doesn't appending to `subs` work with std.array.Appender in
import std.array : Appender;
t.subs ~= T.init; // ERRORS
t.subs.put(T.init); // ERRORS
when it works with builtin arrays as in
s.subs ~= S.init;
t.subs ~= T.init
Error: cannot append type T to type Appender!(T)
Here is the problem:
ElementType!(T) is void.
Here is ElementType:
static if (is(typeof(R.init.front.init) T))
alias ElementType = T;
alias ElementType = void;
So what is happening here (I think), is that T isn't fully defined, so
T.init.front.init is an error at this point. Therefore the else clause
This is one of the problems with using is(typeof) (or
__traits(compiles)) with an "else" clause. You may not be checking what
you think you are checking, and end up with the wrong result.
So essentially, Appender!(T) inside a T becomes (essentially)
Appender!(void). And you can't append a T to a void.
If I change the definition of ElementType to use R.init.front instead of
R.init.front.init, it compiles. But I'm pretty sure this will break
Somewhere, there's an answer.