mixin string evaluation
Artur Skawina
art.08.09 at gmail.com
Sun Jul 21 12:31:51 PDT 2013
On 07/21/13 18:26, Martin Krejcirik wrote:
> Is it somehow possible to evaluate a string on template parameters ?
> Something like this:
>
> enum source = "TYPE var;";
>
> template Eval(TYPE)
> {
> string Eval()
> {
> return evaluate(source); <-- replace TYPE with int
> }
> }
>
> mixin(Eval!int); <-- int var here
>
>
> Basically I need a string mixin inserted into the template before the
> template parameters are evaluated.
Not enough context; I'm not sure what exactly you want to achieve.
The above can simply be done like this:
enum source = "TYPE var;";
mixin template Eval(TYPE) { mixin(source); }
void main() {
mixin Eval!int;
static assert (is(typeof(var) == int));
}
artur
More information about the Digitalmars-d-learn
mailing list