From 4e6e09c568db9cb548e8b45624b334ccf85ff522 Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Tue, 14 Jan 2014 14:46:43 +0000 Subject: [PATCH] std.algorithm: Add test for sorting via proxySwap --- std/algorithm.d | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/std/algorithm.d b/std/algorithm.d index 64c08324702..79130dae5db 100644 --- a/std/algorithm.d +++ b/std/algorithm.d @@ -9182,6 +9182,24 @@ unittest sort!(pred, SwapStrategy.unstable)(arr); assert(comp < 25_000); } + + { + bool proxySwapCalled; + struct S + { + int i; + alias i this; + void proxySwap(ref S other) { swap(i, other.i); proxySwapCalled = true; } + @disable void opAssign(S value); + } + + alias S[] R; + R r = [S(3), S(2), S(1)]; + static assert(hasSwappableElements!R); + static assert(!hasAssignableElements!R); + r.sort(); + assert(proxySwapCalled); + } } private template validPredicates(E, less...) {