why static array can be reassigned with new allocation?
rassoc
rassoc at posteo.de
Sat Oct 15 18:22:10 UTC 2022
On 10/15/22 19:18, mw via Digitalmars-d wrote:
> But the main point I want to make is: these two different semantics should have different syntax, do not overload as it only confuse the programmer.
>
They are not the same thing and behave differently for dynamic and static arrays. Furthermore, there's a distinction between dynamic arrays and slices: ownership of data. [1]
But what you are probably looking for is the follow which is behaving the same as in python:
import std.stdio : writeln;
void main() {
auto a = [1,2,3];
auto b = [1,2,3,4,5];
a = b.dup;
writeln(a is b, " ", a == b); // false true
}
[1] https://dlang.org/articles/d-array-article.html
More information about the Digitalmars-d
mailing list