next_permutation()

Hello. I want to use next permutation on an array of structs i did depending on an integer variable x. Can i do this?
1
2
3
4
struct my_struct{
int x;
....
};
I don't understand what exactly it is you want, can you try explaining it more?
lets say i have a struct s
1
2
3
4
struct s
{
int a,b;
}

and
1
2
3
4
5
6
7
s arr[3];
arr[0].a=1;
arr[0].b=1;
arr[1].a=2;
arr[0].b=1;
arr[2].a=3;
arr[0].b=1;

i want to do next permutation depending on the int a. (there are6 permutations here).
can i do it?
1
2
3
4
5
6
7
8
9
10
#include <vector>

int main()
{
    struct S { S( int a, int b ) : a(a), b(b) {} int a, b ; } ;

    std::vector<S> seq ;

    for( int a : { 1, 2, 3 } ) for( int b : { 4, 5 } ) seq.emplace_back( a, b ) ;
}
Yes, however you need a custom comparison function to determine which of two instances of the struct should be ordered first.
http://www.cplusplus.com/reference/algorithm/next_permutation/?kw=next_permutation
Topic archived. No new replies allowed.