Skip to content

Commit

Permalink
Merge pull request #2651 from quickfur/issue13594b
Browse files Browse the repository at this point in the history
Fix issue 13594: next(Even)Permutation doesn't need to take input range by ref.
  • Loading branch information
Михаил Страшун committed Nov 2, 2014
2 parents 7dfe288 + ef2e431 commit 9add378
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions std/algorithm.d
Expand Up @@ -13228,7 +13228,7 @@ do
* permutation; otherwise returns true.
*/
bool nextPermutation(alias less="a<b", BidirectionalRange)
(ref BidirectionalRange range)
(BidirectionalRange range)
if (isBidirectionalRange!BidirectionalRange &&
hasSwappableElements!BidirectionalRange)
{
Expand Down Expand Up @@ -13403,6 +13403,14 @@ bool nextPermutation(alias less="a<b", BidirectionalRange)
assert(a == [3,2,1]);
}

// Issue 13594
@safe unittest
{
int[3] a = [1,2,3];
assert(nextPermutation(a[]));
assert(a == [1,3,2]);
}

// nextEvenPermutation
/**
* Permutes $(D range) in-place to the next lexicographically greater $(I even)
Expand Down Expand Up @@ -13466,7 +13474,7 @@ do
* permutation; otherwise returns true.
*/
bool nextEvenPermutation(alias less="a<b", BidirectionalRange)
(ref BidirectionalRange range)
(BidirectionalRange range)
if (isBidirectionalRange!BidirectionalRange &&
hasSwappableElements!BidirectionalRange)
{
Expand Down Expand Up @@ -13562,6 +13570,14 @@ bool nextEvenPermutation(alias less="a<b", BidirectionalRange)
assert(b == [ 1, 3, 2 ]);
}

@safe unittest
{
// Issue 13594
int[3] a = [1,2,3];
assert(nextEvenPermutation(a[]));
assert(a == [2,3,1]);
}

/**
Even permutations are useful for generating coordinates of certain geometric
shapes. Here's a non-trivial example:
Expand Down

0 comments on commit 9add378

Please sign in to comment.