Variable references in strings (Was: Structs implementing interfaces

Ary Borenszweig ary at esperanto.org.ar
Tue Feb 10 04:04:44 PST 2009


bearophile wrote:
> Ary Borenszweig:
>> res ~= res ~= "\n\treturn cast(${iface})cast(void*)&_iface_${iface}_vtbl;";
> 
> Have you tried std.metastrings.Format!()? I use it quite often.

template Format(A...)
     Formats constants into a string at compile time. Analogous to 
std.string.format().

     Parameters:
     A = tuple of *constants*, which can be strings, characters, or 
integral values.

I want it in runtime. I basically want this:

foo = `Hello ${var}!`;

or

foo = `Hello $var!`;

to be the same as:

foo = `Hello ` ~ var ~ `!`;

You can see in this trivial example how readability is improved (and you 
type less), and in a bigger example (like the one in this thread) it 
should be better.



More information about the Digitalmars-d mailing list