title: To generate a subset of size n one by one to reduce the complexity?
body: <pre><code>void AlgoMMPCbar::subs(const std::vector&lt;unsigned int&gt;&amp; org, const std::vector&lt;unsigned int&gt;&amp; pre, size_t k, size_t n, SubSets&amp; c){
     if (n &lt;= 1) {
      for(size_t i = k; i &lt; org.size(); i++){
          std::vector&lt;unsigned int&gt; v(pre);// instead of printing...
          v.push_back(org.at(i));
          c.push_back(v);
      }
  } else {
      size_t n1 = n - 1;
      for(size_t i = k; i != org.size() - n1; i++){   // 
          std::vector&lt;unsigned int&gt; s(pre);
          s.push_back(org.at(i));
          subs(org,s,i+1,n1,c);
      }
  }
  }
  void AlgoMMPCbar::computeSubSets(const std::vector&lt;unsigned int&gt;&amp; org, size_t&amp; n, SubSets&amp; c){
   c.clear(); // clear previous data
  
  std::vector&lt;unsigned int&gt; pre;
  pre.reserve(n+1); // for performance
      if (n==0)
        c.push_back(pre);
  else
          subs(org,pre,0, n, c); 
  }
  </code></pre>
  
  <p>The above code used to generate subsets of size n for further test/processing. But i never need to test all these generated subsets (in worst case it will check them all). The main time consuming part of the program is the subset generation. Now i want to transform the above functionality to generate subsets one by one (not all at once, so, i can stop further subset generation any time).</p>
  
  <p>Please share your expertise to transform the above functionality in a function like subset.next(), to save computational time.</p>
  
  <p>Thanks in advance.</p>