Re: specializing template with string variable in CTFE

2014-10-26 Thread ketmar via Digitalmars-d-learn
On Sun, 26 Oct 2014 20:16:18 + via Digitalmars-d-learn wrote: > The documentation specifically says that: > "Any functions that execute at compile time must also be > executable at run time. [...] This means that the semantics of a > function cannot depend on compile time values of the func

Re: specializing template with string variable in CTFE

2014-10-26 Thread via Digitalmars-d-learn
On Sunday, 26 October 2014 at 19:32:28 UTC, ketmar via Digitalmars-d-learn wrote: On Sun, 26 Oct 2014 12:46:06 + via Digitalmars-d-learn wrote: The second possibility doesn't exist right now. The core problem is that the compiler needs to be able to generate runtime code for `buildWrite

Re: specializing template with string variable in CTFE

2014-10-26 Thread ketmar via Digitalmars-d-learn
On Sun, 26 Oct 2014 12:46:06 + via Digitalmars-d-learn 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, albei

Re: specializing template with string variable in CTFE

2014-10-26 Thread ketmar via Digitalmars-d-learn
On Sun, 26 Oct 2014 12:46:06 + via Digitalmars-d-learn wrote: > The second possibility doesn't exist right now. The core problem > is that the compiler needs to be able to generate runtime code > for `buildWriter()`, because it's just a function after all. but it's templated function, and i

Re: specializing template with string variable in CTFE

2014-10-26 Thread via Digitalmars-d-learn
On Sunday, 26 October 2014 at 10:48:46 UTC, ketmar via Digitalmars-d-learn wrote: Hello. the following code is not working: template prstr(string s) { enum prstr = "write("~s.stringof~");\n"; } string buildWriter() (string fmt) { return prstr!(fmt[0..$-1]); } string writer(s

Re: specializing template with string variable in CTFE

2014-10-26 Thread via Digitalmars-d-learn
On Sunday, 26 October 2014 at 12:27:55 UTC, Marc Schütz wrote: On Sunday, 26 October 2014 at 10:48:46 UTC, ketmar via Digitalmars-d-learn wrote: Hello. the following code is not working: template prstr(string s) { enum prstr = "write("~s.stringof~");\n"; } string buildWriter() (string f

Re: specializing template with string variable in CTFE

2014-10-26 Thread via Digitalmars-d-learn
On Sunday, 26 October 2014 at 10:48:46 UTC, ketmar via Digitalmars-d-learn wrote: Hello. the following code is not working: template prstr(string s) { enum prstr = "write("~s.stringof~");\n"; } string buildWriter() (string fmt) { return prstr!(fmt[0..$-1]); } Your passing the