#include #include template std::set powerset(const Set& s, size_t n) { typedef typename Set::const_iterator SetCIt; typedef typename std::set::const_iterator PowerSetCIt; std::set res; if(n > 0) { std::set ps = powerset(s, n-1); for(PowerSetCIt ss = ps.begin(); ss != ps.end(); ss++) for(SetCIt el = s.begin(); el != s.end(); el++) { Set subset(*ss); subset.insert(*el); res.insert(subset); } res.insert(ps.begin(), ps.end()); } else res.insert(Set()); return res; } template std::set powerset(const Set& s) { return powerset(s, s.size()); }