Fix container ctors and opAssign ref parameters

Container constructors and opAssign should accept any ref container and
not only const, otherwise the source container will be copied because
the constructor/opAssign without ref would be a better match.
This commit is contained in:
Eugen Wissner 2017-05-01 09:48:12 +02:00
parent 65c3ca14ec
commit f2aac680c5
3 changed files with 16 additions and 18 deletions

View File

@ -215,16 +215,19 @@ struct SList(T)
* If $(D_PARAM init) is passed by reference, it will be copied.
*
* Params:
* R = Source list type.
* init = Source list.
* allocator = Allocator.
*/
this(ref SList init, shared Allocator allocator = defaultAllocator)
this(R)(ref R init, shared Allocator allocator = defaultAllocator)
if (is(Unqual!R == SList))
{
this(init[], allocator);
}
/// Ditto.
this(SList init, shared Allocator allocator = defaultAllocator) @trusted
this(R)(R init, shared Allocator allocator = defaultAllocator) @trusted
if (is(R == SList))
{
this(allocator);
if (allocator is init.allocator)
@ -734,18 +737,19 @@ struct SList(T)
*
* Returns: $(D_KEYWORD this).
*/
ref typeof(this) opAssign(R)(const ref R that)
ref typeof(this) opAssign(R)(ref R that)
if (is(Unqual!R == SList))
{
return this = that[];
}
/// Ditto.
ref typeof(this) opAssign(R)(const ref R that)
if (is(Unqual!R == SList))
ref typeof(this) opAssign(R)(R that)
if (is(R == SList))
{
swap(this.head, that.head);
swap(this.allocator_, that.allocator_);
return this;
}
/**

View File

@ -225,11 +225,11 @@ struct Vector(T)
* If $(D_PARAM init) is passed by reference, it will be copied.
*
* Params:
* R = Vector type.
* R = Source vector type.
* init = Source vector.
* allocator = Allocator.
*/
this(R)(const ref R init, shared Allocator allocator = defaultAllocator)
this(R)(ref R init, shared Allocator allocator = defaultAllocator)
if (is(Unqual!R == Vector))
{
this(allocator);
@ -1413,7 +1413,7 @@ struct Vector(T)
*
* Returns: $(D_KEYWORD this).
*/
ref typeof(this) opAssign(R)(const ref R that)
ref typeof(this) opAssign(R)(ref R that)
if (is(Unqual!R == Vector))
{
return this = that[];

View File

@ -245,16 +245,10 @@ struct Integer
ref Integer opAssign(T)(T value) nothrow @safe @nogc
if (is(T == Integer))
{
if (this.allocator is value.allocator)
{
swap(this.rep, value.rep);
swap(this.sign, value.sign);
swap(this.size, value.size);
}
else
{
this = value;
}
swap(this.rep, value.rep);
swap(this.sign, value.sign);
swap(this.size, value.size);
swap(this.allocator_, value.allocator_);
return this;
}