I would like to compile something like the following:
import std.meta: AliasSeq;
import std.stdio: writeln;
class Bag {
template fill(alias types) {
void fill() {
writeln("Do stuff");
}
}
}
void main(){
auto bag = new Bag();
alias stuff = AliasSeq!(int, ubyte[]);
bag.fill!(stuff)();
}
But I cannot get this to compile. Is there a bug in the code I am not seeing, or is there something more fundamentally wrong?
You just used the wrong kind of argument to the template. Try template fill(types...)
instead of template fill(alias types)
and it should compile.
An AliasSeq
is a sequence of template arguments and corresponds to a variadic ...
thing instead of a single symbol, which is what an alias
thing does.