Accept only ranges for slicing assignment
This commit is contained in:
parent
87b74b2542
commit
405b6d9f9f
@ -273,8 +273,7 @@ private struct Range(E)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Range opSliceAssign(R)(R value, in size_t i, in size_t j)
|
Range opSliceAssign(R)(R value, in size_t i, in size_t j)
|
||||||
if ((isStaticArray!R && isImplicitlyConvertible!(ElementType!R, T))
|
if (isStaticArray!R && isImplicitlyConvertible!(ElementType!R, T))
|
||||||
|| is(R == Vector))
|
|
||||||
{
|
{
|
||||||
return opSliceAssign(value[], i, j);
|
return opSliceAssign(value[], i, j);
|
||||||
}
|
}
|
||||||
@ -535,10 +534,8 @@ struct Vector(T)
|
|||||||
}
|
}
|
||||||
bool overflow;
|
bool overflow;
|
||||||
immutable byteSize = mulu(size, T.sizeof, overflow);
|
immutable byteSize = mulu(size, T.sizeof, overflow);
|
||||||
if (overflow)
|
assert(!overflow);
|
||||||
{
|
|
||||||
onOutOfMemoryErrorNoGC();
|
|
||||||
}
|
|
||||||
void[] buf = vector[0 .. capacity_];
|
void[] buf = vector[0 .. capacity_];
|
||||||
if (!allocator.expand(buf, byteSize))
|
if (!allocator.expand(buf, byteSize))
|
||||||
{
|
{
|
||||||
@ -741,14 +738,12 @@ struct Vector(T)
|
|||||||
&& isImplicitlyConvertible!(ElementType!R, T))
|
&& isImplicitlyConvertible!(ElementType!R, T))
|
||||||
{
|
{
|
||||||
immutable rLen = walkLength(el);
|
immutable rLen = walkLength(el);
|
||||||
immutable newLen = length_ + rLen;
|
|
||||||
|
|
||||||
reserve(newLen);
|
reserve(length_ + rLen);
|
||||||
initializeAll(vector[length_ .. newLen]);
|
|
||||||
T* pos = vector + length_;
|
T* pos = vector + length_;
|
||||||
foreach (e; el)
|
foreach (e; el)
|
||||||
{
|
{
|
||||||
*pos = e;
|
emplace(pos, e);
|
||||||
++length_, ++pos;
|
++length_, ++pos;
|
||||||
}
|
}
|
||||||
return rLen;
|
return rLen;
|
||||||
@ -1259,14 +1254,14 @@ struct Vector(T)
|
|||||||
* Slicing assignment.
|
* Slicing assignment.
|
||||||
*
|
*
|
||||||
* Params:
|
* Params:
|
||||||
* value = New value.
|
* value = New value (single value or input range).
|
||||||
* i = Slice start.
|
* i = Slice start.
|
||||||
* j = Slice end.
|
* j = Slice end.
|
||||||
*
|
*
|
||||||
* Returns: Slice with the assigned part of the vector.
|
* Returns: Slice with the assigned part of the vector.
|
||||||
*
|
*
|
||||||
* Precondition: $(D_INLINECODE i <= j && j <= length);
|
* Precondition: $(D_INLINECODE i <= j && j <= length);
|
||||||
* The lenghts of the ranges and slices match.
|
* The lenghts of the range and slice match.
|
||||||
*/
|
*/
|
||||||
Range!T opSliceAssign(ref T value, in size_t i, in size_t j) @trusted
|
Range!T opSliceAssign(ref T value, in size_t i, in size_t j) @trusted
|
||||||
in
|
in
|
||||||
@ -1276,7 +1271,7 @@ struct Vector(T)
|
|||||||
}
|
}
|
||||||
body
|
body
|
||||||
{
|
{
|
||||||
fill(vector[i .. j], value);
|
vector[i .. j] = value;
|
||||||
return opSlice(i, j);
|
return opSlice(i, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1293,6 +1288,8 @@ struct Vector(T)
|
|||||||
&& isImplicitlyConvertible!(ElementType!R, T))
|
&& isImplicitlyConvertible!(ElementType!R, T))
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
assert(i <= j);
|
||||||
|
assert(j <= length);
|
||||||
assert(j - i == walkLength(value));
|
assert(j - i == walkLength(value));
|
||||||
}
|
}
|
||||||
body
|
body
|
||||||
@ -1307,8 +1304,7 @@ struct Vector(T)
|
|||||||
|
|
||||||
/// Ditto.
|
/// Ditto.
|
||||||
Range!T opSliceAssign(R)(R value, in size_t i, in size_t j)
|
Range!T opSliceAssign(R)(R value, in size_t i, in size_t j)
|
||||||
if ((isStaticArray!R && isImplicitlyConvertible!(ElementType!R, T))
|
if (isStaticArray!R && isImplicitlyConvertible!(ElementType!R, T))
|
||||||
|| is(R == Vector))
|
|
||||||
{
|
{
|
||||||
return opSliceAssign(value[], i, j);
|
return opSliceAssign(value[], i, j);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user