Fix DList.opAssign not changing tail

This commit is contained in:
Eugen Wissner 2017-06-28 08:12:58 +02:00
parent 2af0db04bd
commit a6dfb3a19e
1 changed files with 113 additions and 68 deletions

View File

@ -174,6 +174,12 @@ struct SList(T)
assert(l.front == 3);
}
private @safe @nogc unittest
{
auto l = SList!int(0, 0);
assert(l.empty);
}
/// Ditto.
this(const size_t len, shared Allocator allocator = defaultAllocator)
{
@ -610,9 +616,7 @@ struct SList(T)
}
/**
* Returns the first element and moves to the next one.
*
* Returns: The first element.
* Removes the front element.
*
* Precondition: $(D_INLINECODE !empty)
*/
@ -763,6 +767,23 @@ struct SList(T)
return this;
}
///
@safe @nogc unittest
{
{
auto l1 = SList!int([5, 4, 9]);
auto l2 = SList!int([9, 4]);
l1 = l2;
assert(l1 == l2);
}
{
auto l1 = SList!int([5, 4, 9]);
auto l2 = SList!int([9, 4]);
l1 = SList!int([9, 4]);
assert(l1 == l2);
}
}
/**
* Assigns an input range.
*
@ -805,12 +826,20 @@ struct SList(T)
assert(l1 == l2);
}
private @safe @nogc unittest
{
auto l1 = SList!int();
auto l2 = SList!int([9, 4]);
l1 = l2[];
assert(l1 == l2);
}
/**
* Assigns a static array.
*
* Params:
* R = Static array size.
* that = Values to initialize the vector with.
* that = Values to initialize the list with.
*
* Returns: $(D_KEYWORD this).
*/
@ -1063,6 +1092,12 @@ struct DList(T)
assert(l.back == 3);
}
private @safe @nogc unittest
{
auto l = DList!int(0, 0);
assert(l.empty);
}
/// Ditto.
this(const size_t len, shared Allocator allocator = defaultAllocator)
{
@ -1356,16 +1391,20 @@ struct DList(T)
assert(l1.insertFront(8) == 1);
assert(l1.front == 8);
assert(l1.back == 8);
assert(l1.insertFront(9) == 1);
assert(l1.front == 9);
assert(l1.back == 8);
DList!int l2;
assert(l2.insertFront([25, 30, 15]) == 3);
assert(l2.front == 25);
assert(l2.back == 15);
l2.insertFront(l1[]);
assert(l2.length == 5);
assert(l2.front == 9);
assert(l2.back == 15);
}
/**
@ -1655,9 +1694,7 @@ struct DList(T)
}
/**
* Returns the first element and moves to the next one.
*
* Returns: The first element.
* Removes the front element.
*
* Precondition: $(D_INLINECODE !empty)
*/
@ -1838,20 +1875,20 @@ struct DList(T)
{
Entry** next = &this.head;
foreach (ref e; that)
while (!that.empty && *next !is null)
{
if (*next is null)
(*next).content = that.front;
next = &(*next).next;
that.popFront();
}
if (that.empty)
{
*next = allocator.make!Entry(e);
remove(DRange!T(*next, this.tail));
}
else
{
(*next).content = e;
insertBack(that);
}
next = &(*next).next;
}
remove(DRange!T(*next, this.tail));
return this;
}
@ -1864,12 +1901,20 @@ struct DList(T)
assert(l1 == l2);
}
private @safe @nogc unittest
{
auto l1 = DList!int();
auto l2 = DList!int([9, 4]);
l1 = l2[];
assert(l1 == l2);
}
/**
* Assigns a static array.
*
* Params:
* R = Static array size.
* that = Values to initialize the vector with.
* that = Values to initialize the list with.
*
* Returns: $(D_KEYWORD this).
*/