Type of string literal concatenated with non-immutable char array
Per Nordlöw
per.nordlow at gmail.com
Mon Feb 1 11:49:15 UTC 2021
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 array, those breaking the immutability. Example:
I still don't understand why that restriction applies to arrays
of values types (such as `char`). Having this limitation makes my
code example more bloated or less efficient memorywise; I either
have to define two separate ctors or force an .idup at the site
of the exception construction.
More information about the Digitalmars-d-learn
mailing list