On Friday, 14 February 2014 at 02:41:12 UTC, bearophile wrote:
Meta:
alias list1 = Cons!(Three, Cons!(Two, Cons!(Four, Cons!(One,
Nil))));
alias numlHead(L: Cons!(a, b), a, b) = a;
alias numlTail(L: Cons!(a, b), a, b) = b;
But the compiler is complaining loudly about a mismatch:
/d43/f234.d(39): Error: template instance numlHead!(list1)
does not match template declaration numlHead(L : Cons!(a, b),
a, b)
See a recent thread of mine:
http://forum.dlang.org/thread/vlwgufdlpjgewpnnh...@forum.dlang.org
Currently I think you have to accept types and aliases with a
regular template syntax, and verify the types and kinds with
template constraints. Something like (untested):
template numlTail(C) if (TemplateOf!(C, Cons)) {
alias numlTail = TemplateArgsOf!(C)[1];
}
Bye,
bearophile
It seems strange that it would choke now, as Cons is a struct.
Therefore, Cons!(Three, ...) should create a new type, and `L:
Cons!(a, b), a, b` shouldn't be any trouble to destructure into
two types, `Three` and `Cons!(Two, ...)`. It had no problem
handling the Succ and Number struct templates I defined.