I have a c++ vector
with std::pair<unsigned long, unsigned long>
objects. I am trying to generate permutations of the objects of the vector using std::next_permutation()
. However, I want the permutations to be of a given size, you know, similar to the permutations
function in python where the size of the expected returned permutation is specified.
Basically, the c++
equivalent of
import itertools
list = [1,2,3,4,5,6,7]
for permutation in itertools.permutations(list, 3):
print(permutation)
Python Demo
(1, 2, 3)
(1, 2, 4)
(1, 2, 5)
(1, 2, 6)
(1, 2, 7)
(1, 3, 2)
(1, 3, 4)
..
(7, 5, 4)
(7, 5, 6)
(7, 6, 1)
(7, 6, 2)
(7, 6, 3)
(7, 6, 4)
(7, 6, 5)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…