format()
Jonathan M Davis
jmdavisProg at gmx.com
Sun Jun 12 13:11:27 PDT 2011
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