fix next|prev_permutation implementations