Skip to content

Commit

Permalink
std.algorithm: Add test for sorting via proxySwap
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberShadow committed Jan 14, 2014
1 parent 9e14a1f commit 4e6e09c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions std/algorithm.d
Expand Up @@ -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...) {
Expand Down

0 comments on commit 4e6e09c

Please sign in to comment.