Create mixins from a list of strings
Jakob Ovrum
jakobovrum at gmail.com
Fri Jan 10 23:50:50 PST 2014
On Saturday, 11 January 2014 at 07:45:31 UTC, Casper Færgemand
wrote:
> Have:
> enum (or is immutable array better?) array = ["derp", "lala"];
>
> Want:
> mixin("some syntax" ~ array[0]);
> mixin("some syntax" ~ array[1]);
You can use template argument lists for indexable compile-time
lists:
---
import std.typetuple : TypeTuple;
alias array = TypeTuple!("derp", "lala");
mixin("some syntax" ~ array[0]);
mixin("some syntax" ~ array[1]);
---
> Basically, to specify a number of similar functions based on a
> list of strings.
> Why? Pegged's semantic actions allows only calling a function
> by name, not specifying parameters. I could probably ask for an
> extension, but if there's a cool template or whatever way to do
> this, it would be a lot nicer. :3
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.
More information about the Digitalmars-d-learn
mailing list