format()

Lloyd Dupont ld-REMOVE at galador.net
Sun Jun 12 17:54:51 PDT 2011


yep, the example is simple because it is an example!
Thanks for your suggestion! :)

"Jonathan M Davis"  wrote in message 
news:mailman.850.1307909499.14074.digitalmars-d-learn at puremagic.com...

On 2011-06-12 10:30, David Nadlinger wrote:
> On 6/12/11 6:37 PM, Lloyd Dupont wrote:
> > mm... ok.
> > but why the line below doesn't compile?
> >
> > mixin(format("class %s {}", "A"));
>
> Because format presumably can't be interpreted at compile time (yet) –
> not all functions are necessarily CTFEable.

Yeah. format can only be used at runtime. If you want a version which works 
at
compile time, then you std.metastrings.Format, which is an eponymous 
template.
e.g.

mixin(Format!("class %s {}", "A"));

should work. Of course, in this particular case, you might as well just give
the whole string to the mixin directly, but I assume that the example is so
simple simply because it's an example.

- Jonathan M Davis 



More information about the Digitalmars-d-learn mailing list