Reference or Value Semantics for Graph Traversal Range
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Feb 18 06:07:01 PST 2015
On 2/18/15 8:59 AM, "Nordlöw" wrote:
> On Wednesday, 18 February 2015 at 13:53:17 UTC, Tobias Pankrath wrote:
>>> All the data members except distMap have reference semantics.
>>
>> I thought AAs had reference semantics.
>
> Me too, but the indeed have value semantics. See for example:
>
> unittest
> {
> string[int] x;
> auto y = x;
> x[0] = "zero";
> assert(x != y);
> }
This is a well known problem.
An UNINITIALIZED AA has not yet been allocated, and so it's reference is
null.
But once initialized, it DOES have reference semantics:
string[int] x;
x[0] = "zero";
auto y = x;
x[1] = "one";
assert(x == y);
And to anticipate your question, no there is no way (yet) to create an
empty but initialized AA.
-Steve
More information about the Digitalmars-d-learn
mailing list