Merge branch 'master' into utf8string

This commit is contained in:
Eugen Wissner 2017-05-02 10:59:00 +02:00
commit c3b63ee40d

View File

@ -976,6 +976,7 @@ struct Vector(T)
* Assigns a value to the element with the index $(D_PARAM pos). * Assigns a value to the element with the index $(D_PARAM pos).
* *
* Params: * Params:
* E = Value type.
* value = Value. * value = Value.
* pos = Position. * pos = Position.
* *
@ -983,58 +984,45 @@ struct Vector(T)
* *
* Precondition: $(D_INLINECODE length > pos). * Precondition: $(D_INLINECODE length > pos).
*/ */
ref T opIndexAssign(ref T value, const size_t pos) ref T opIndexAssign(E : T)(auto ref E value, const size_t pos)
{ {
return opIndex(pos) = value; return opIndex(pos) = value;
} }
@safe unittest /// Ditto.
Range!T opIndexAssign(E : T)(auto ref E value)
{
return opSliceAssign(value, 0, length);
}
///
nothrow @safe @nogc unittest
{ {
Vector!int a = Vector!int(1); Vector!int a = Vector!int(1);
a[0] = 5; a[0] = 5;
assert(a[0] == 5); assert(a[0] == 5);
} }
/// Ditto.
T opIndexAssign(T value, const size_t pos)
{
return opIndexAssign(value, pos);
}
/// Ditto.
Range!T opIndexAssign(T value)
{
return opSliceAssign(value, 0, length);
}
/// Ditto.
Range!T opIndexAssign(ref T value)
{
return opSliceAssign(value, 0, length);
}
/** /**
* Assigns a range or a static array. * Assigns a range or a static array.
* *
* Params: * Params:
* R = Range type or static array length. * R = Value type.
* value = Value. * value = Value.
* *
* Returns: Assigned value. * Returns: Assigned value.
* *
* Precondition: $(D_INLINECODE length == value.length). * Precondition: $(D_INLINECODE length == value.length).
*/ */
Range!T opIndexAssign(R)(R value) Range!T opIndexAssign(size_t R)(T[R] value)
if (!isInfinite!R && isInputRange!R
&& isImplicitlyConvertible!(ElementType!R, T))
{ {
return opSliceAssign!R(value, 0, length); return opSliceAssign!R(value, 0, length);
} }
/// Ditto. /// Ditto.
Range!T opIndexAssign(size_t R)(T[R] value) Range!T opIndexAssign(Range!T value)
{ {
return opSliceAssign!R(value, 0, length); return opSliceAssign(value, 0, length);
} }
/// ///
@ -1296,9 +1284,9 @@ struct Vector(T)
* Slicing assignment. * Slicing assignment.
* *
* Params: * Params:
* R = Type of the assigned slice or length of the static array should be * R = Type of the assigned slice or length of the static array should
* assigned. * be assigned.
* value = New value (single value, input range or static array). * value = New value (single value, range or static array).
* i = Slice start. * i = Slice start.
* j = Slice end. * j = Slice end.
* *
@ -1307,30 +1295,22 @@ struct Vector(T)
* Precondition: $(D_INLINECODE i <= j && j <= length * Precondition: $(D_INLINECODE i <= j && j <= length
* && value.length == j - i) * && value.length == j - i)
*/ */
Range!T opSliceAssign(R)(R value, const size_t i, const size_t j) @trusted Range!T opSliceAssign(size_t R)(T[R] value, const size_t i, const size_t j)
if (!isInfinite!R @trusted
&& isInputRange!R
&& isImplicitlyConvertible!(ElementType!R, T))
in in
{ {
assert(i <= j); assert(i <= j);
assert(j <= length); assert(j <= length);
assert(j - i == walkLength(value));
} }
body body
{ {
copy(value, this.data[i .. j]); copy(value[], this.data[i .. j]);
return opSlice(i, j); return opSlice(i, j);
} }
/// Ditto. /// Ditto.
Range!T opSliceAssign(size_t R)(T[R] value, const size_t i, const size_t j) Range!T opSliceAssign(R : T)(auto ref R value, const size_t i, const size_t j)
{ @trusted
return opSliceAssign!(T[])(value[], i, j);
}
/// Ditto.
Range!T opSliceAssign(ref T value, const size_t i, const size_t j) @trusted
in in
{ {
assert(i <= j); assert(i <= j);
@ -1343,9 +1323,17 @@ struct Vector(T)
} }
/// Ditto. /// Ditto.
Range!T opSliceAssign(T value, const size_t i, const size_t j) Range!T opSliceAssign(Range!T value, const size_t i, const size_t j) @trusted
in
{ {
return opSliceAssign(value, i, j); assert(i <= j);
assert(j <= length);
assert(j - i == value.length);
}
body
{
copy(value, this.data[i .. j]);
return opSlice(i, j);
} }
/// ///