digitalmars.D.learn - mixin string evaluation
- Martin Krejcirik (15/15) Jul 21 2013 Is it somehow possible to evaluate a string on template parameters ?
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (19/32) Jul 21 2013 import std.algorithm;
- Martin Krejcirik (5/13) Jul 21 2013 Thanks, actually findSplit is what I need, but works like a charm. CTFE
- Artur Skawina (10/28) Jul 21 2013 Not enough context; I'm not sure what exactly you want to achieve.
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. -- mk
Jul 21 2013
On 07/21/2013 09:26 AM, 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.import std.algorithm; enum source = "TYPE var;"; template Eval(TYPE) { string Eval() { string statement = source; auto found = statement.findSkip("TYPE"); assert(found); return TYPE.stringof ~ statement; } } void main() { mixin(Eval!int); static assert(is (typeof(var) == int)); } Ali
Jul 21 2013
On 21.7.2013 19:15, Ali Çehreli wrote:string Eval() { string statement = source; auto found = statement.findSkip("TYPE"); assert(found); return TYPE.stringof ~ statement; }Thanks, actually findSplit is what I need, but works like a charm. CTFE rox ! -- mk
Jul 21 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
Jul 21 2013