Discussion Thread: DIP 1036--String Interpolation Tuple Literals--Community Review Round 2
Paul Backus
snarwin at gmail.com
Wed Feb 3 22:15:45 UTC 2021
On Wednesday, 3 February 2021 at 22:07:47 UTC, Daniel N wrote:
> On Wednesday, 3 February 2021 at 20:12:24 UTC, Adam D. Ruppe
> wrote:
>> On Wednesday, 3 February 2021 at 20:02:57 UTC, Daniel N wrote:
>>> Wouldn't this lowering be both simpler and more more
>>> efficient?
>>
>> Your change wouldn't expose the string for compile' time
>> processing.
>>
>> That's the real benefit of interp!"string" - it is available
>> for CTFE rewriting by the function.
>
> Guess it's not allowed to keep discussing in the feedback
> thread so I have to copy it here.
>
> alias I(T...) = T;
> alias X(T...) = I!(interp!(T[0]), interp!(T[1]));
>
> Sorry for being daft, I simply don't get it... there's no issue
> with applying map to a tuple of string literals...
> X!("one","two")
The idea is that, even when `interp!"whatever"` is passed as a
*runtime* argument to a template function, that function can
access the string "whatever" at compile time, because it's part
of the argument's *type* rather than its *value*.
void fun(Args...)(Args args)
{
static foreach (arg; args) {
static if (is(arg == interp!s, string s)) {
// Allowed to do this because `s` is known at compile
time
pragma(msg, s);
}
}
}
// prints "Hello " at compile-time
fun(i"Hello ${name}");
More information about the Digitalmars-d
mailing list