Discussion Thread: DIP 1036--String Interpolation Tuple Literals--Community Review Round 2
Q. Schroll
qs.il.paperinik at gmail.com
Thu Feb 4 18:54:19 UTC 2021
On Thursday, 4 February 2021 at 18:14:59 UTC, Q. Schroll wrote:
> Formally, the compiler has to try the __interp and the string
> version. If both succeed (that's the relevant case) and
> instantiate THE SAME template, the string version (i.e. idup)
> will be used. Otherwise, the __interp is a better match and
> will be used.
I want to add how this works when using interpolated strings as
template parameters. If templ is a template, templ!i"Hello
${name}, it's me!", also both rewrites are tried. If the only
template is like this
template templ(args...) { ... }
it will make args.length == 1 and args[0] == "Hello "~name~",
it's me!". To match an interp sequence, one needs an overload
like this
template templ(args...)
if (args.length > 0 && is(typeof(args[0]) == interp!str,
string str))
{ ... }
that matches no string, but an interp object. The case is
relevant because one might want to handle the parts specially
even though @nogc and stuff is no concern for compile-time
constructs.
The same as aforementioned, you cannot have one template that
fits all and decides later.
More information about the Digitalmars-d
mailing list