String Interpolation
IGotD-
nise at nise.com
Mon Oct 30 17:26:27 UTC 2023
On Monday, 30 October 2023 at 16:43:14 UTC, Arafel wrote:
>
> 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.
Thank you for this and alias this wasn't even on my mind. We need
more posts like this, solutions and how to move forward. In 99%
of the cases, you don't care what string interpolation is
underneath and just want a string or parameter from it. The
string interpolation implementation can even change over time.
More information about the Digitalmars-d
mailing list