Skip to content

Commit b9f8783

Browse files
committed
Make ~= return a reference to self
1 parent 9da0afa commit b9f8783

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/containers/dynamicarray.d

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ struct DynamicArray(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
2828

2929
static if (is(typeof((T[] a, const T[] b) => a[0 .. b.length] = b[0 .. $])))
3030
{
31-
/// Either const(T) or T.
31+
/// Either `const(T)` or `T`.
3232
alias AppendT = const(T);
3333

34-
/// Either const(typeof(this)) or typeof(this).
34+
/// Either `const(typeof(this))` or `typeof(this)`.
3535
alias AppendTypeOfThis = const(typeof(this));
3636
}
3737
else
@@ -156,15 +156,16 @@ struct DynamicArray(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
156156
/**
157157
* ~= operator overload
158158
*/
159-
void opOpAssign(string op)(T value) if (op == "~")
159+
scope ref typeof(this) opOpAssign(string op)(T value) if (op == "~")
160160
{
161161
insert(value);
162+
return this;
162163
}
163164

164165
/**
165166
* ~= operator overload for an array of items
166167
*/
167-
void opOpAssign(string op, bool checkForOverlap = true)(AppendT[] rhs)
168+
scope ref typeof(this) opOpAssign(string op, bool checkForOverlap = true)(AppendT[] rhs)
168169
if (op == "~" && !is(T == AppendT[]))
169170
{
170171
// Disabling checkForOverlap when this function is called from opBinary!"~"
@@ -175,7 +176,7 @@ struct DynamicArray(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
175176
{
176177
// Special case where rhs is a slice of this array.
177178
this = this ~ rhs;
178-
return;
179+
return this;
179180
}
180181
reserve(l + rhs.length);
181182
import std.traits: hasElaborateAssign, hasElaborateDestructor;
@@ -210,13 +211,14 @@ struct DynamicArray(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
210211
arr[l .. l + rhs.length] = rhs[0 .. rhs.length];
211212
l += rhs.length;
212213
}
214+
return this;
213215
}
214216

215217
/// ditto
216-
void opOpAssign(string op)(ref AppendTypeOfThis rhs)
218+
scope ref typeof(this) opOpAssign(string op)(ref AppendTypeOfThis rhs)
217219
if (op == "~")
218220
{
219-
this ~= rhs.arr[0 .. rhs.l];
221+
return this ~= rhs.arr[0 .. rhs.l];
220222
}
221223

222224
/**

0 commit comments

Comments
 (0)