Token strings as "cheap" macros.
Reiner Pope
some at address.com
Fri Sep 7 04:52:06 PDT 2007
Daniel Keep wrote:
>
> 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
What, the formatting can be evaluated at compile-time?
-- Reiner
More information about the Digitalmars-d
mailing list