Deque impl.

d coder dlang.coder at gmail.com
Thu Jan 31 03:34:33 PST 2013


On Thu, Jan 31, 2013 at 2:43 PM, Robert burner Schadek
<realburner at gmx.de> wrote:
> Thats not totally correct. The Rb tree is a class. But the real reason for
> the Deque being a class
> is that it holds two value members. And if you pass the Deque around you
> need to do this as ref.
> Otherwise you shall not call any method that modifies this value members,
> because this will only be
> visible at the calling site.

I would expect all the containers in the std.container to have either
pass by value or pass by reference semantics. It seems at least Array,
Slist, and Dlist are structs and they follow pass by value semantics.

>From Dlang.org:

auto a = DList!int([3, 4]); //Create a new chain
auto b = a; //Point to the same chain
// (3 - 4)
assert(a[].equal([3, 4]));
assert(b[].equal([3, 4]));

b.stableInsertFront(1); //insert before of b
b.stableInsertBack(5); //insert after of b
// (2 - (3 - 4) - 5)
assert(a[].equal([3, 4])); //a is not changed
assert(b[].equal([1, 3, 4, 5])); // but b is changed


Regards
- Puneet


More information about the Digitalmars-d mailing list