Safe copy-paste using mixin

drug via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 31 04:05:20 PDT 2015


On 31.08.2015 13:57, Andrea Fontana wrote:
>
> Just create a function that return a string with those three lines and
> mixin it!
>
> Like:
>
> import std.stdio;
>
> string toMix( string a, string b, string c)
> {
>      return `string a = "` ~ a ~ `";` ~ `string b = "` ~ b ~ `";`
> `string c = "` ~ c ~ `";`;
> }
>
>
> void main()
> {
>
>      {
>          mixin(toMix("hello", " world", " 1"));
>          writeln(a,b,c);
>      }
>
>      {
>          mixin(toMix("hello", " world", " 2"));
>          writeln(a,b,c);
>      }
> }
As usual in D the answer is simple.)

But sometimes string mixins aren't desired, it would be nice to mixin 
the code, not strings.


More information about the Digitalmars-d-learn mailing list