Merge pull request #682 from jmdavis/swap

Workaround for bug# 4789 removed.
This commit is contained in:
Andrei Alexandrescu 2012-08-05 15:38:02 -07:00
commit 8cddf7d176

View file

@ -1665,12 +1665,16 @@ if (isMutable!T && !is(typeof(T.init.proxySwap(T.init))))
}
else
{
// Temporary fix Bug 4789. Wor around the fact that assigning a static
// array to itself doesn't work properly.
static if(isStaticArray!T) {
if(lhs.ptr is rhs.ptr) {
//Avoid assigning overlapping arrays. Dynamic arrays are fine, because
//it's their ptr and length properties which get assigned rather
//than their elements when assigning them, but static arrays are value
//types and therefore all of their elements get copied as part of
//assigning them, which would be assigning overlapping arrays if lhs
//and rhs were the same array.
static if(isStaticArray!T)
{
if(lhs.ptr == rhs.ptr)
return;
}
}
// For non-struct types, suffice to do the classic swap
@ -1749,6 +1753,13 @@ unittest
static assert(!__traits(compiles, swap(const1, const2)));
}
unittest
{
//Bug# 4789
int[1] s = [1];
swap(s, s);
}
void swapFront(R1, R2)(R1 r1, R2 r2)
if (isInputRange!R1 && isInputRange!R2)
{