Discussion Thread: DIP 1036--String Interpolation Tuple Literals--Community Review Round 2

Adam D. Ruppe destructionator at gmail.com
Fri Jan 29 04:47:41 UTC 2021


On Friday, 29 January 2021 at 04:25:54 UTC, Walter Bright wrote:
> Interesting, but it's really writing your own printf, and one 
> that doesn't accept any format modifiers.

It is trivial to accept format modifiers here too, his example 
just generated them from type info because you can.

It could just as well be

printf(i"%s${item} %02d${other_item}");

which expands to the inlinable call

printf("%s %02d", item, other_item);

by means of simple metaprogramming (you concat the strings at 
compile time - no runtime cost, it reduces to an eponymous 
template with an enum string - then build the call out of the 
remaining filtered tuple).

You can even do a CTFE scan of the string if you like and see 
that there's a % already and use it, or there isn't one and 
insert one.

While this is an overload to do the CTFE manipulations, they are 
indeed CTFE manipulations and thus have no runtime footprint; it 
reduces to an inlined call to the original thing. Same assembly.

D excels at these things.


More information about the Digitalmars-d mailing list