Vkladanie kódu (mixins)

The mixin expression takes an arbitrary string and compiles it and generates instructions accordingly. It is purely a compile-time mechanism and can only work on strings available during compilation - a comparison with the evil JavaScript eval would be highly unfair.

mixin("int b = 5");
assert(b == 5); // compiles just fine

mixin also works with strings that are constructed dynamically as long as the available information doesn't depend on runtime values.

mixin together with CTFE from the next section allows writing impressive libraries like Pegged which generates a grammar parser from a grammar defined as a string in the source code.

In-depth

rdmd playground.d