Skip to content

Commit af54d58

Browse files
committed
Update to new for-loop protocol
1 parent c67a85a commit af54d58

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/libcore/vec.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1790,23 +1790,23 @@ pub fn each2_mut<U, T>(v1: &mut [U], v2: &mut [T], f: &fn(u: &mut U, t: &mut T)
17901790
*
17911791
* * `fun` - The function to iterate over the combinations
17921792
*/
1793-
pub fn each_permutation<T:Copy>(values: &[T], fun: &fn(perm : &[T]) -> bool) {
1793+
pub fn each_permutation<T:Copy>(values: &[T], fun: &fn(perm : &[T]) -> bool) -> bool {
17941794
let length = values.len();
17951795
let mut permutation = vec::from_fn(length, |i| values[i]);
17961796
if length <= 1 {
17971797
fun(permutation);
1798-
return;
1798+
return true;
17991799
}
18001800
let mut indices = vec::from_fn(length, |i| i);
18011801
loop {
1802-
if !fun(permutation) { return; }
1802+
if !fun(permutation) { return true; }
18031803
// find largest k such that indices[k] < indices[k+1]
18041804
// if no such k exists, all permutations have been generated
18051805
let mut k = length - 2;
18061806
while k > 0 && indices[k] >= indices[k+1] {
18071807
k -= 1;
18081808
}
1809-
if k == 0 && indices[0] > indices[1] { return; }
1809+
if k == 0 && indices[0] > indices[1] { return true; }
18101810
// find largest l such that indices[k] < indices[l]
18111811
// k+1 is guaranteed to be such
18121812
let mut l = length - 1;

0 commit comments

Comments
 (0)