[phobos] expand for std.metastrings
kenji hara
k.hara.pg at gmail.com
Sat Nov 6 06:45:25 PDT 2010
Thanks, all.
Through the discussion, I supported following suggestions:
- Add non-string values formatting. (Andrei)
- Add type formatting. (Robert)
- Identifier expression can ommit braces. (Andrei)
- Add expandSplit makes comma separated code-sting.
(i.e. expandSplit!"call $n times" generates q{`call `, n, ` times`}.)
And, I decided keeps expand's name.
If no other comments, I'd like to post to issue-tracker, and commit.
Kenji
2010/11/1 kenji hara <k.hara.pg at gmail.com>:
> I wrote a trivial utility template for generating code string.
> This provides some easiness and viewability of metaprogramming.
> (This is currently used in my adaptTo.)
>
> http://github.com/9rnsr/scrap/blob/master/expand/expand.d
>
> Sample:
> ----
> template GenFunc(string name)
> {
> mixin(
> mixin(expand!q{
> int ${name}(){ return 10; }
> }));
> // result of expand! is:
> // q{`int ` ~ name ~ `(){ return 10; }`}
> }
> mixin GenFunc!("test"); // generates function "test" returns int
> unittest{
> assert(test() == 10);
> }
> ----
>
> expand!q{ codes... } parses D code string, and expands ${ expr } for
> embedding expr that is expression evaluated as string in compile-time.
>
> do you think?
>
> Kenji
>
More information about the phobos
mailing list