specializing template with string variable in CTFE

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Oct 26 12:33:58 PDT 2014


On Sun, 26 Oct 2014 12:46:06 +0000
via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com> wrote:

> Ok, I see two possibilities. The first is to make `prstr` into a 
> normal function. You cannot use `stringof` then, but need to 
> escape the string yourself. Luckily, std.format provides 
> functionality for this already, albeit a bit hidden:
> 
>      private auto escapeStringLiteral(string s) {
>          import std.format : formatElement, FormatSpec;
>          import std.range : appender;
> 
>          auto app = appender!string;
>          FormatSpec!char f;
>          formatElement(app, s, f);
> 
>          return app.data;
>      }
thank you, this is very handy. yet my desire to instantiate template
with compile-time variable still remains. ;-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141026/c9f9f912/attachment.sig>


More information about the Digitalmars-d-learn mailing list