import std.stdio;
void main(){
int[] m = [1,2,3];
m = m ~ 4 ~ 5; // ok
m ~= 4 ~ 5; // not work
}
Comment #1 by lodovico — 2016-07-20T20:11:04Z
(In reply to Danila Letunovskiy from comment #0)
> import std.stdio;
>
> void main(){
> int[] m = [1,2,3];
>
> m = m ~ 4 ~ 5; // ok
>
> m ~= 4 ~ 5; // not work
> }
It works as intended. binary ops have precedence over assignment ops, so your last expression is equivalent to
m ~= (4 ~ 5);
And (4 ~ 5) does not make sense, because ~ is defined when at least one operand is an array.
What you want is one of these two (probably the first):
(m ~= 4) ~= 5;
m ~= [4] ~ 5;