// Finding fermion basis states using 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(Nstates,0); // 0 occupation by default for (int i=0; i!=N; ++i) {vec[i]=1;} // occupy single-fermion states 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(); }