Typed variadic template syntax?
Idan Arye
GenericNPC at gmail.com
Thu Jan 30 12:18:11 PST 2014
On Thursday, 30 January 2014 at 14:08:27 UTC, Ilya Yaroshenko
wrote:
> 1) You can use
> mixin(format("<Prolog>%(<Begin>%s<End>%)<Epilog>",
> CompileTimeRange)); See std.format for ranges and
> std.string.format.
That works for simple cases. Complex cases require that you write
a function and calling it with CTFE for creating the mixin
string. This can be a problem outside functions, because you are
polluting the namespace. It might not be that bad for structs and
classes, since you can simply make that helper function private -
but for template mixins the helper function must be exposed to
the code that uses the mixin.
Having complex strings mixing also means that if there is a
problem in that string, the compiler will point to the line where
the string is mixed in, not the one where the code that
introduces the error is concentrated to the string. Having a
static foreach will make the string mixins small and simple
enough for this to not be a problem.
Metaprogramming by building the code strings is not something
that should be encouraged(*cough* C macros *cough*), but it's
currently required sometimes for complex metaprogramming in D. If
we had static foreach we would still need string mixins, but at
least we will be mixing in many small simple strings instead of
one big complex string, and that means we could add to Phobos
some helper template mixins for sanitizing the arguments for
those mixins.
More information about the Digitalmars-d
mailing list