Concatenating with a string array

Thomas Kuehne thomas-dloop at kuehne.cn
Thu Feb 23 23:32:06 PST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Walter Bright schrieb am 2006-02-15:
>
> "Nick" <Nick_member at pathlink.com> wrote in message 
> news:dshvbk$qop$1 at digitaldaemon.com...
>> This should work, shouldn't it?
>>
>> void main()
>> {
>> char[][] a;
>> a ~= "hello";    // Works
>> a = a ~ "world"; // Error
>> }
>>
>> tst.d(5): incompatible types for ((a) ~ ("world")): 'char[][]' and 
>> 'char[5]'
>> tst.d(5): Can only concatenate arrays, not (char[][] ~ char[5])
>> tst.d(5): cannot implicitly convert expression ((a) ~ "world") of type int 
>> to
>> char[][]
>
> The a~="hello" should work because ~= can do two different things:
>
> 1) append an element to an array
> 2) append an array of elements to an array
>
> The a~="hello" is an example of (1).
>
> The a=a~"hello" should not work, because ~ only does (2). I'm a little 
> concerned that modifying it to do (1) as well will introduce unanticipated 
> problems. 

The documentation of "array ~= x" seems a bit vague.
(http://digitalmars.com/d/arrays.html) only documents (2) not (1).

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFD/rqU3w+/yD4P9tIRAvm0AJ9ANAnttjBLDgrDeEo4PxjtdgMNYQCfcmk8
oRYsDKYliGegsqLZwx2g9RY=
=tCN3
-----END PGP SIGNATURE-----



More information about the Digitalmars-d-bugs mailing list