you can think of it as a sort of .. intelligent,
type-safe macro. but only sort of.
mixins are expanded (inlined) when they are used,
so you can use it to insert code.
void PrintMessage() { writefln("message!");
}
template Fork { PrintMessage(); }
void main()
{
mixin Fork;
}
a pretty useless example, but it will call PrintMessage() when you use mixin Fork. it's because it expands inline
so the mixin Fork line in main() becomes:
PrintMessage();
the more interesting stuff you can do with a mixin
is when you use parameters.
template Spoon(T) { T num; }
void main()
{
mixin
Spoon!(float);
num=5.5;
}
personally i don't use them that often and i think
they are of limited usefulness.. but they're there. and they're
interesting.