aboutsummaryrefslogtreecommitdiff
path: root/libphobos/src/std/algorithm/mutation.d
diff options
context:
space:
mode:
Diffstat (limited to 'libphobos/src/std/algorithm/mutation.d')
-rw-r--r--libphobos/src/std/algorithm/mutation.d23
1 files changed, 23 insertions, 0 deletions
diff --git a/libphobos/src/std/algorithm/mutation.d b/libphobos/src/std/algorithm/mutation.d
index ea1a1b2..8a45ecb 100644
--- a/libphobos/src/std/algorithm/mutation.d
+++ b/libphobos/src/std/algorithm/mutation.d
@@ -2885,6 +2885,17 @@ if (isBlitAssignable!T && !is(typeof(lhs.proxySwap(rhs))))
{
if (&lhs != &rhs)
{
+ static if (__traits(compiles, lhs.tupleof = rhs.tupleof))
+ {
+ if (__ctfe)
+ {
+ // can't reinterpret cast
+ foreach (i, ref e; lhs.tupleof)
+ swap(e, rhs.tupleof[i]);
+ return;
+ }
+ }
+
// For structs with non-trivial assignment, move memory directly
ubyte[T.sizeof] t = void;
auto a = (cast(ubyte*) &lhs)[0 .. T.sizeof];
@@ -3128,6 +3139,18 @@ if (isBlitAssignable!T && !is(typeof(lhs.proxySwap(rhs))))
swap(a3, a4);
}
+// https://issues.dlang.org/show_bug.cgi?id=21429
+@safe unittest
+{
+ enum e = (){
+ Tuple!int a = 5, b = 6;
+ swap(a, b);
+ assert(a[0] == 6);
+ assert(b[0] == 5);
+ return 0;
+ }();
+}
+
/**
Swaps two elements in-place of a range `r`,
specified by their indices `i1` and `i2`.