String Interpolation

Arafel er.krali at gmail.com
Mon Oct 30 16:43:14 UTC 2023


On 30/10/23 13:54, IGotD- wrote:
> Nor having any form of implicit conversions in the language is a limitation.

Oh, but we do: it's called "alias this".

It would be totally possible to lower the interpolation to a struct with 
an `alias this` that points to a default `toString` method that would do 
basic concatenation.

If you think it will help you secure your code, you can have your 
function **only** accept the lowered struct. Otherwise, you can have a 
string overload in addition to / instead of that.

If you don't care where your string parameter comes from, you just act 
as usual, keep using strings, and let the users construct them however 
they prefer.

Now, the usual argument against this is that it ties the "low level" 
compiler to a "high level" feature like string formatting (for floats, 
for instance).

I understand the concern. However, most of the code is already there 
used in `pragma(msg, ...)` and in `static assert`, so at most it would 
need to add a call to `toString` (if present) for aggregated types.


More information about the Digitalmars-d mailing list