String Mixins
You’ll learn about string mixins in this lesson.
We'll cover the following...
Another powerful feature of D the ability to insert code as string as long as that string is known at compile time. The syntax of string mixins requires the use of parentheses:
mixin (compile_time_generated_string)
For example, the hello world program can also be written with a mixin:
Press + to interact
import std.stdio;void main() {mixin (`writeln("Hello, World!");`);}
The string gets inserted as code.
We can go further and insert all of the program as a string mixin:
Press + to interact
import std.stdio;mixin (`import std.stdio; void main() { writeln("Hello, World!"); }`);
Obviously, there is no need for mixins in these examples, as the strings could have been written as code.
The power of string mixins comes from the fact that the code can be generated at compile time. The ...