Is it possible to use std::next_permutation() to permutate the elements of a vector of a class i created?
How does the comparison parameter in next_permutation() work?
Is it possible to use std::next_permutation() to permutate the elements of a vector of a class i created?
How does the comparison parameter in next_permutation() work?
Yes!
Try this
This might help
Yes, the simplest way is to override operator< within your class in which case you don't need to worry about comp.
The comp parameter is a function pointer which takes two iterators to the vector and returns true or false depending on how you'd want them ordered.
Edit: Untested but for what it's worth:
Sure thing; you just need to pass an iterator to the first element and one to the one-after-last element, as usual with STL algorithms.
It's a functor used to compare elements of your vector (or container in general); it should behave as any < operator would do: return true if the first element is less than the second, false otherwise, thus establishing an order relation between your objects. Note that, as all the comparison operators, it must follow some rules (here explained in a slightly different context, but they are always the same).
By the way, if you define a < operator for your class you can simply use the first overload (the one with just the iterators as parameters) and avoid creating a separate functor.