Fix issue 13594: next(Even)Permutation doesn't need to take input range by ref.

This commit is contained in:
H. S. Teoh 2014-10-31 13:15:51 -07:00
parent 947a526393
commit ef2e43181b

View file

@ -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)
{
@ -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)
@ -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)
{
@ -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: