Implicit conversion of concatenation result to immutable

Ali Çehreli acehreli at yahoo.com
Thu Apr 1 22:07:09 UTC 2021


On 4/1/21 2:59 PM, H. S. Teoh wrote:

 > the result of concatenating two
 > const(char)[] must be const(char)[], since you don't know if one of them
 > may have mutable aliases somewhere else.  So the result must likewise be
 > const(char)[].
 >
 > One may argue that appending in general will reallocate, and once
 > reallocated it will be unique, and there safe to implicitly convert to
 > immutable.  However, in general we cannot guarantee this

Yes, that's tricky for append because one of many slices does own the 
potential bytes after the array and will append elements in there. 
However, concatenation always makes a new array, right? I think the 
result can be char[] in that case.

Ali



More information about the Digitalmars-d mailing list