Discussion Thread: DIP 1036--Formatted String Tuple Literals--Community Review Round 1
Paul Backus
snarwin at gmail.com
Sat Sep 12 13:44:47 UTC 2020
On Saturday, 12 September 2020 at 12:37:14 UTC, Andrei
Alexandrescu wrote:
> On 9/11/20 5:36 PM, Stefan Koch wrote:
>>
>> could be a compiler tuple which doesn't need std nor object.d.
>
> Shouldn't because it needs to be expandable on demand, not
> implicitly.
The only way I can think of to do this that works in the general
case is something like the following:
// Before
writeln(i"Hello $name!".expand);
// After
template Pack(Args...)
{
alias expand = Args;
}
auto ref __interpexpr1() { return name; }
writeln(Pack!("Hello ", __interpexpr1, "!").expand);
The reason you can't use a struct (that is, a "run=time tuple")
is that the mapping from *expressions* to *values* is not
injective--it discards information about ref-ness and lazy-ness
(and maybe others I haven't thought of?). And the reason you have
to "quote" each expression by wrapping it in a function is that
template argument lists only accept symbols, not expressions.
I'm not sure if I like this better or worse than DIP 1027's
"naked argument list" approach.
More information about the Digitalmars-d
mailing list