// Using C++ Standard Library algorithm next_permutation // #include #include #include #include namespace my { template struct State{ T i; std::vector v; State(T ind,std::vector vec) {i=ind; v=std::move(vec);} void print(){ std::cout<<"state # "<> states; std::vector vec={0,1,2,3,4}; std::sort(vec.begin(),vec.end()); // make sure next_permutation starts ok int i = 1; do { states.push_back(my::State(i,vec)); i++; } while (next_permutation (vec.begin(),vec.end())); for (auto s:states) s.print(); } // state # 1 ( 0 1 2 3 4 ) // ... // state # 120 ( 4 3 2 1 0 )