4 ms·
D mixin templates/mixins are another alternative: You can include arbitrary strings from functions running at compile time. Theoretically they're more powerful
by FrozenVoid 9y ago
D mixin templates/mixins are another alternative:
You can include arbitrary strings from functions running at compile time.
Theoretically they're more powerful than C macros, but type safety(template parameters) makes some constructs awkward - unless you create and parse strings as tokens manually(basically reading/writing many strings to achieve what C preprocessor does with symbolic token composition).
https://dlang.org/mixin.html https://dlang.org/mixin.html
https://dlang.org/spec/template-mixin.html https://dlang.org/spec/template-mixin.html
Templates can also include mixins:
template liter(String s){mixin(s);}