title: Why can't I generate all permutations with std::next_permutation?
body: <p>I'm trying to obtain all permutations of binary values (which, in this case, are represented by integers 0 and 1) using the <a href="https://en.cppreference.com/w/cpp/algorithm/next_permutation" rel="nofollow noreferrer">std::next_permutation</a> from the C++14 STL.</p>
  <p>However, I do think that I found a bug in this method.<br />
  If the vector has <strong>one or more zeros</strong> on its <strong>end</strong>, then one <strong>cannot</strong> obtain all permutations of the vector.</p>
  <p>For instance, let's consider the vector <code>std::vector&lt;int&gt; a = {1,0,0}</code>. The only permutation found by <code>std::next_permutation</code> is <code>{(1 0 0)}</code>, whereas there exists three possible permutations <code>{(1 0 0), (0 1 0), (0 0 1)}</code>.</p>
  <p>Is this a bug? If so, where can I report it?</p>
  <p>You can access my code in C++ shell <a href="http://cpp.sh/9xago" rel="nofollow noreferrer">here</a>. It is also displayed below.</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  
  int main() {
  
    std::vector&lt;int&gt; a = {1,0,0,0};
    std::vector&lt;int&gt; b = {0,0,0,1};
  
    std::cout &lt;&lt; &quot;Permutations of a&quot; &lt;&lt; std::endl;
    do {
      for (int i = 0; i &lt; a.size(); i++) {
        std::cout &lt;&lt; a[i];
      }
    std::cout &lt;&lt; std::endl;
    } while (std::next_permutation(a.begin(), a.end()));
    
    
    std::cout &lt;&lt; std::endl &lt;&lt; &quot;Permutations of b&quot; &lt;&lt; std::endl;
    
    do {
      for (int i = 0; i &lt; b.size(); i++) {
        std::cout &lt;&lt; b[i];
      }
      std::cout &lt;&lt; std::endl;
    } while (std::next_permutation(b.begin(), b.end()));
    exit(0);
  }
  </code></pre>
  <p>Output:</p>
  <pre><code>Permutations of a
  1000
  
  Permutations of b
  0001
  0010
  0100
  1000
  </code></pre>