Skip to content

Commit 2b1c98e

Browse files
authored
Merge pull request #6295 from carblue/std_container_slist
std.container.slist: Fix a @safe cannot call @System issue merged-on-behalf-of: Walter Bright <[email protected]>
2 parents 52b99f4 + 1443d75 commit 2b1c98e

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

dip1000.mak

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ aa[std.zlib]=-dip1000
6060
aa[std.algorithm.comparison]=-dip1000
6161
aa[std.algorithm.internal]=-dip1000
6262
aa[std.algorithm.iteration]=-dip25 # WIP_carblue
63-
aa[std.algorithm.mutation]=-dip25 # depends on std.container.slist (https://github.com/dlang/phobos/pull/6295)
63+
aa[std.algorithm.mutation]=-dip1000
6464
aa[std.algorithm.package]=-dip1000
6565
aa[std.algorithm.searching]=-dip25 # depends on https://github.com/dlang/phobos/pull/6246 merged and std.algorithm.comparison fixed
6666
aa[std.algorithm.setops]=-dip1000
@@ -95,7 +95,7 @@ aa[std.container.binaryheap]=-dip1000
9595
aa[std.container.dlist]=-dip1000
9696
aa[std.container.package]=-dip1000
9797
aa[std.container.rbtree]=-dip25 # DROP
98-
aa[std.container.slist]=-dip25 # -dip1000 -version=DIP1000 depends on https://github.com/dlang/phobos/pull/6295 merged
98+
aa[std.container.slist]=-dip1000 -version=DIP1000 # merged https://github.com/dlang/phobos/pull/6295
9999
aa[std.container.util]=-dip25 # TODO
100100

101101
aa[std.datetime.date]=-dip25 # depends on a fix for writefln

std/container/slist.d

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,22 @@ struct SList(T)
138138
/**
139139
Constructor taking a number of nodes
140140
*/
141-
this(U)(U[] values...) if (isImplicitlyConvertible!(U, T))
141+
this(U)(scope U[] values...) if (isImplicitlyConvertible!(U, T))
142142
{
143-
insertFront(values);
143+
initialize();
144+
Node* n, newRoot;
145+
foreach (item; values)
146+
{
147+
auto newNode = new Node(null, item);
148+
(newRoot ? n._next : newRoot) = newNode;
149+
n = newNode;
150+
}
151+
if (n)
152+
{
153+
// Last node points to the old root
154+
n._next = _first;
155+
_first = newRoot;
156+
}
144157
}
145158

146159
/**
@@ -359,7 +372,7 @@ Complexity: $(BIGOH m), where $(D m) is the length of $(D stuff)
359372
{
360373
initialize();
361374
size_t result;
362-
Node * n, newRoot;
375+
Node* n, newRoot;
363376
foreach (item; stuff)
364377
{
365378
auto newNode = new Node(null, item);
@@ -911,3 +924,15 @@ Complexity: $(BIGOH n)
911924
s.reverse();
912925
assert(s[].equal([3, 2, 1]));
913926
}
927+
928+
version(DIP1000)
929+
@safe unittest
930+
{
931+
int i, j;
932+
auto s = SList!(int*)([&i, &j]);
933+
assert(s._root);
934+
assert(s._root._next);
935+
assert(s._root._next._next);
936+
assert(s._root._next._payload == &i);
937+
assert(s._root._next._next._payload == &j);
938+
}

0 commit comments

Comments
 (0)