String Interpolation

IGotD- nise at nise.com
Fri Oct 27 13:20:33 UTC 2023


On Friday, 27 October 2023 at 12:55:35 UTC, Arafel wrote:
>
> 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.

Why does this work?

void func(string a)
{
...
}

func("string literal");



More information about the Digitalmars-d mailing list