String Interpolation

Arafel er.krali at gmail.com
Fri Oct 27 12:55:35 UTC 2023


On 27/10/23 13:59, Imperatorn wrote:
>     Can't this be solved by adding a constructor in the string class
>     that accepts whatever type the interpolated string is?
> 
> Would be nice yes
> 

Not possible. A string in D is just another name (literally, just an 
alias) for an array of immutable chars. So there is no string class, and 
no constructor to speak of, other than the generic array constructor.

Technically, the best solution would probably be to return a (templated) 
struct with an "alias this" to the already interpolated string, and all 
other interpolation information also included, so functions would be 
able to choose what to accept.

But "alias this" is just a way to have implicit casting, and that's 
something (probably rightly) opposed here on principle, so I don't think 
we'll be having it anytime soon.


More information about the Digitalmars-d mailing list