type of concatenated arrays
BCS
BCS at pathlink.com
Wed Nov 7 14:57:18 PST 2007
Janice Caron wrote:
> On 11/7/07, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
>
>
>>Now, a2 is declared as a const(char)[] array, but I think it should be just
>>a char[] array. Why? because the concat operator should have made a copy
>>of the array with length +1 and added the \n character. If this is the
>>case, I should be able to do whatever I want with the copy. Why does it
>>have to be const?
>
>
> Because of copy-on-write.
>
> If b is the empty string, then (a ~ b) will evaluate to a. No copy need be made.
from the spec:
"Concatenation always creates a copy of its operands, even if one of the
operands is a 0 length array"
http://www.digitalmars.com/d/arrays.html
grep for "~" and look down about 8 lines
More information about the Digitalmars-d
mailing list