Reference or Value Semantics for Graph Traversal Range

Tobias Pankrath via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Feb 18 06:26:38 PST 2015


On Wednesday, 18 February 2015 at 13:59:43 UTC, 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 makes usage of storing internal state in Ranges bug-prone.
>
>
> Isn't there some way to store an AA in reference wrapper?
>
> This would simplify my .save member.

Because y does not alias x, it's a null pointer like AA. This 
class is clearly a reference type, but the assert holds as well.

class C { int i; }

void main()
{
         C c1;
         C c2 = c1;
         c1 = new C(12);
         assert(c1.i != c2.i);
}









More information about the Digitalmars-d-learn mailing list