Type of string literal concatenated with non-immutable char array
ag0aep6g
anonymous at example.com
Mon Feb 1 12:17:08 UTC 2021
On 31.01.21 22:48, Per Nordlöw wrote:
> Why isn't
>
> "Name " ~ name ~ " could not be found"
>
> implicitly convertible to `string`?
If concatenation is guaranteed to allocate a new array, then it should
be "strongly pure", and the conversion should work. I'm not sure if it
is guaranteed to allocate a new array.
> Would
>
> class NameLookupException : Exception
> {
> this(scope const(char)[] name) @trusted {
> super("Name " ~ cast(string)name ~ " could not be found");
> }
> }
>
> be ok?
Only if you know for sure that you're dealing with a compiler bug here.
As another workaround, you can use std.conv.text:
import std.conv: text;
super(text("Name ", name, " could not be found"));
More information about the Digitalmars-d-learn
mailing list