Re: Type of string literal concatenated with non-immutable char array

2021-02-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/1/21 11:31 AM, Per Nordlöw wrote: On Monday, 1 February 2021 at 16:30:31 UTC, Per Nordlöw wrote: Btw, does     x ~ y ~ z ~ ... result in a single allocation? Provided all the operands has a `length` property. As long as they are all arrays, yes, the compiler calls a single runtime ca

Re: Type of string literal concatenated with non-immutable char array

2021-02-01 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 1 February 2021 at 15:47:33 UTC, Steven Schveighoffer wrote: "Concatenation always creates a copy of its operands, even if one of the operands is a 0 length array" Btw, does x ~ y ~ z ~ ... result in a single allocation?

Re: Type of string literal concatenated with non-immutable char array

2021-02-01 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 1 February 2021 at 16:30:31 UTC, Per Nordlöw wrote: Btw, does x ~ y ~ z ~ ... result in a single allocation? Provided all the operands has a `length` property.

Re: Type of string literal concatenated with non-immutable char array

2021-02-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/1/21 7:17 AM, ag0aep6g wrote: 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 n

Re: Type of string literal concatenated with non-immutable char array

2021-02-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/31/21 4:48 PM, Per Nordlöw wrote: Why isn't     "Name " ~ name ~ " could not be found" implicitly convertible to `string`? One of my oldest Enhancement requests: https://issues.dlang.org/show_bug.cgi?id=1654 -Steve

Re: Type of string literal concatenated with non-immutable char array

2021-02-01 Thread ag0aep6g via Digitalmars-d-learn
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 allo

Re: Type of string literal concatenated with non-immutable char array

2021-02-01 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 1 February 2021 at 10:27:29 UTC, Jacob Carlborg wrote: Why isn't "Name " ~ name ~ " could not be found" implicitly convertible to `string`? Because if you have arrays of reference types, it's possible to change an element of the mutable array, which will affect the immutable

Re: Type of string literal concatenated with non-immutable char array

2021-02-01 Thread Jacob Carlborg via Digitalmars-d-learn
On Sunday, 31 January 2021 at 21:48:09 UTC, Per Nordlöw wrote: Given char x[]; why is typeof("a" ~ x) `char[]` when typeof("a" ~ x.idup) is `string`? My case is class NameLookupException : Exception { this(string name) { super("Name " ~ name ~ " could not be f

Type of string literal concatenated with non-immutable char array

2021-01-31 Thread Per Nordlöw via Digitalmars-d-learn
Given char x[]; why is typeof("a" ~ x) `char[]` when typeof("a" ~ x.idup) is `string`? My case is class NameLookupException : Exception { this(string name) { super("Name " ~ name ~ " could not be found"); } this(scope const(char)[] name) { super