diff --git a/dip1000.mak b/dip1000.mak index e1e24e4a29a..e148c5fbddd 100644 --- a/dip1000.mak +++ b/dip1000.mak @@ -60,7 +60,7 @@ aa[std.zlib]=-dip1000 aa[std.algorithm.comparison]=-dip1000 aa[std.algorithm.internal]=-dip1000 aa[std.algorithm.iteration]=-dip25 # WIP_carblue -aa[std.algorithm.mutation]=-dip25 # depends on std.container.slist (https://github.com/dlang/phobos/pull/6295) +aa[std.algorithm.mutation]=-dip1000 aa[std.algorithm.package]=-dip1000 aa[std.algorithm.searching]=-dip25 # depends on https://github.com/dlang/phobos/pull/6246 merged and std.algorithm.comparison fixed aa[std.algorithm.setops]=-dip1000 @@ -95,7 +95,7 @@ aa[std.container.binaryheap]=-dip1000 aa[std.container.dlist]=-dip1000 aa[std.container.package]=-dip1000 aa[std.container.rbtree]=-dip25 # DROP -aa[std.container.slist]=-dip25 # -dip1000 -version=DIP1000 depends on https://github.com/dlang/phobos/pull/6295 merged +aa[std.container.slist]=-dip1000 -version=DIP1000 # merged https://github.com/dlang/phobos/pull/6295 aa[std.container.util]=-dip25 # TODO aa[std.datetime.date]=-dip25 # depends on a fix for writefln diff --git a/std/container/slist.d b/std/container/slist.d index 8c2f2fc6dfb..fa814e2f7ee 100644 --- a/std/container/slist.d +++ b/std/container/slist.d @@ -138,9 +138,22 @@ struct SList(T) /** Constructor taking a number of nodes */ - this(U)(U[] values...) if (isImplicitlyConvertible!(U, T)) + this(U)(scope U[] values...) if (isImplicitlyConvertible!(U, T)) { - insertFront(values); + initialize(); + Node* n, newRoot; + foreach (item; values) + { + auto newNode = new Node(null, item); + (newRoot ? n._next : newRoot) = newNode; + n = newNode; + } + if (n) + { + // Last node points to the old root + n._next = _first; + _first = newRoot; + } } /** @@ -359,7 +372,7 @@ Complexity: $(BIGOH m), where $(D m) is the length of $(D stuff) { initialize(); size_t result; - Node * n, newRoot; + Node* n, newRoot; foreach (item; stuff) { auto newNode = new Node(null, item); @@ -911,3 +924,15 @@ Complexity: $(BIGOH n) s.reverse(); assert(s[].equal([3, 2, 1])); } + +version(DIP1000) +@safe unittest +{ + int i, j; + auto s = SList!(int*)([&i, &j]); + assert(s._root); + assert(s._root._next); + assert(s._root._next._next); + assert(s._root._next._payload == &i); + assert(s._root._next._next._payload == &j); +}