Create mixins from a list of strings
Timon Gehr
timon.gehr at gmx.ch
Sat Jan 11 12:52:14 PST 2014
On 01/11/2014 09:35 AM, "Casper Færgemand" <shorttail at hotmail.com>" wrote:
> On Saturday, 11 January 2014 at 07:50:51 UTC, Jakob Ovrum wrote:
>> Your problem is probably better solved without string mixins, but we'd
>> probably need to see some code or more elaboration to accurately
>> suggest a solution.
>
> enum semanticArray = ["test"];
>
> mixin(`T ` ~ semanticArray[0] ~ `(T)(T t) {
> t.name ~= "` ~ semanticArray[0] ~ `";
> return t;
> }`);
>
> This will mixin a single templated function named "test", which changes
> an AST node's name to whatever it was concatenated with "test". I want
> this to happen automatically for any length of semanticArray.
import std.string, std.algorithm;
enum semanticArray = ["derp", "lala"];
mixin(semanticArray.map!(a=>`T `~a~`(T)(T t) {
t.name ~= "`~a~`";
return t;
}`).join());
More information about the Digitalmars-d-learn
mailing list