specializing template with string variable in CTFE

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Oct 26 13:39:35 PDT 2014


On Sun, 26 Oct 2014 20:16:18 +0000
via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com> 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 function."
> 
> http://dlang.org/function.html
> 
> I can imagine it would be difficult to implement it differently, 
> because in effect the compiler would need to create a new 
> instance of the function for every call, with each instance 
> potentially being completely different (consider `static if` over 
> CTFE runtime parameters).
leaving away technical complexities for compiler writers, i like to say
that restrictions for templated functions can be relaxed. maybe by
marking some templates/functions as "CTFE-only". or just fix semantic
analyser to allow some more things in CTFE. such template will never
instantiates successfully for run-time code, and it still can be used
in metaprogramming.

writing purely functional templates really sux. i made a simple
writef-like module which parses it's format string in compile time and
i must admit that some templates has 10+ arguments and keep growing as
i adding features. either this, or even more convoluted hacks.

alas, i'm still don't understand compiler code deep enough to see how
hard this will be to implement.
-------------- 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/376c3ba0/attachment.sig>


More information about the Digitalmars-d-learn mailing list