Bug in using string mixins inside of a struct?

Joseph Cassman jc7919 at outlook.com
Tue Mar 26 16:28:33 PDT 2013


On Tuesday, 26 March 2013 at 23:00:40 UTC, Timon Gehr wrote:
> On 03/26/2013 10:28 PM, Joseph Cassman wrote:
>> [...]
>
> Bad code. Use enum for compile-time constants.
>
> This will work:
>
> struct A{
>     void b(){
>         size_t y;
>         mixin(c!("y"));
>     }
>
>     template c(string x){
>         enum c = "while(" ~ x ~ " < 100){" ~ x ~ "++;}";
>     }
> }

I agree. No need for the memory allocation in this case.
Perhaps the example on the tutorial page could be updated 
accordingly.

http://dlang.org/mixin.html

Appreciate the help

Joseph


More information about the Digitalmars-d mailing list