title: Trying to simulate python combinations in C++ with next_permutation
body: <p>I need to port a snippet written in Python to C++ 
  but that snippet is using combinations from itertools in python.</p>
  
  <p>The line that I'm really interested to porting over to C++ is this one:</p>
  
  <pre><code>for k in combinations(range(n-i),2*i):
  </code></pre>
  
  <p><code>range(n-i)</code> in Python will generate a list from <code>0 to (n-i) - 1</code></p>
  
  <p>Let n = 16, i = 5</p>
  
  <p><code>print range(n-i)</code></p>
  
  <p>outputs:</p>
  
  <p><code>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]</code></p>
  
  <p>and python combinations will generate all possible  combinations in that list.</p>
  
  <p>e.g.</p>
  
  <p><code>print list(combinations(range(n-i),2*i))</code></p>
  
  <p>outputs:</p>
  
  <pre>
  [(0, 1, 2, 3, 4, 5, 6, 7, 8, 9),
  (0, 1, 2, 3, 4, 5, 6, 7, 8, 10),
  (0, 1, 2, 3, 4, 5, 6, 7, 9, 10),
  (0, 1, 2, 3, 4, 5, 6, 8, 9, 10),
  (0, 1, 2, 3, 4, 5, 7, 8, 9, 10),
  (0, 1, 2, 3, 4, 6, 7, 8, 9, 10),
  (0, 1, 2, 3, 5, 6, 7, 8, 9, 10),
  (0, 1, 2, 4, 5, 6, 7, 8, 9, 10),
  (0, 1, 3, 4, 5, 6, 7, 8, 9, 10),
  (0, 2, 3, 4, 5, 6, 7, 8, 9, 10),
  (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)]
  </pre>
  
  <p>I want to generate similar output using <code>std::vector</code> and <code>next_permutation</code> from C++ but I'm still getting erroneous results. This is my current approach:</p>
  
  <pre><code>for(int j = 0; j &lt; n-i; j++) {
          temp_vector.push_back(j); 
  }
  </code></pre>
  
  <p>That snippet is equivalent to <code>range(n-i)</code> in Python.</p>
  
  <p>But the following snippet:</p>
  
  <pre><code>do {
       myvector.push_back(temp_vector);
  } while(next_permutation(temp_vector.begin(),temp_vector.begin()+2*i));
  cout&lt;&lt;myvector.size()&lt;&lt;endl;
  </code></pre>
  
  <p>Is not equivalent to <code>combinations(range(n-i),2*i))</code> in Python, and I've tried many variations and still haven't been able to come up with the results I'm expecting.</p>
  
  <p>For example:</p>
  
  <p>Let n = 16
  i = 5</p>
  
  <p><strong>Python</strong></p>
  
  <p><code>&gt;&gt;&gt; print len(list(combinations(range(n-i),2*i)))</code></p>
  
  <p><code>11</code></p>
  
  <p><strong>C++</strong></p>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  int main() {
      vector&lt;int&gt; temp_vector;
      vector&lt; vector&lt;int&gt; &gt; myvector;
      int n = 16, i = 5;
      for(int j = 0; j &lt; n - i; j++) {
              temp_vector.push_back(j);
      }
      do {
              myvector.push_back(temp_vector);
      } while(next_permutation(temp_vector.begin(), temp_vector.begin()+2*i));
      cout&lt;&lt;myvector.size()&lt;&lt;endl;
      return 0;
  }
  </code></pre>
  
  <p><code>g++ combinations.cpp</code></p>
  
  <p><code>./a.out</code></p>
  
  <p><code>3628800</code></p>
  
  <p>Any guidance will be greatly appreciated! Thanks a lot!</p>