Token strings as "cheap" macros.
Daniel Keep
daniel.keep.lists at gmail.com
Fri Sep 7 03:29:54 PDT 2007
Reiner Pope wrote:
> [snip]
>
> I made my own compile-time formatter. I made one based on Phobos
> formatting, and then I decided I preferred indexable style (like Tango),
> so I've got one of each: formatStringTango and formatStringPhobos. Just
> now, I added a wrapper function for formatStringTango which allows
> expressions instead of indexes. Here's the unittest:
>
> unittest
> {
> const x = 5;
> const y = 7;
> static assert(mixin(format("{x} = 5, {y} = 7")) == "5 = 5, 7 = 7");
> }
>
> I've attached the source code. It's full of other templates I made to
> help work around problems with metaprogramming (__traits in particular),
> but it at least shows that it's pretty much achievable within the
> language. Of course, macros would be nice, to remove the mixin().
>
> -- Reiner
>
I've made one too :)
http://while-nan.blogspot.com/2007/06/mixins-ctfe-and-shell-style-variable.html
-- Daniel
More information about the Digitalmars-d
mailing list