title: generate_n using lambda and back_inserter in C++
body: <p>I've recently started using new C++11 features like lambda expressions to make my code easier to read.</p>
  
  <p>In this example, I want to generate a vector of numbers [0 to n] sorted randomly. I have some code similar to the following</p>
  
  <pre><code>    #include &lt;vector&gt;
      #include &lt;algorithm&gt;
      #include &lt;iterator&gt;
      using namespace std;
      void _generateRandomIndices(vector&lt;unsigned int&gt; &amp; indices,
                  const unsigned int &amp; n) {
          indices.clear();
          unsigned int i = 0;
          generate_n(back_inserter(indices), n , [&amp;i] ()-&gt; unsigned int{ 
                                                                return i++;
                                                                       } );
          random_shuffle(indices.begin(), indices.end());
      } 
  </code></pre>
  
  <p>However, using g++ 4.6 on windows(with the -std=c++0x flag) threw me the following error: </p>
  
  <pre><code>no matching function for call to 'generate_n(std::back_insert_iterator&lt;std::vector&lt;unsigned int&gt; &gt;, const unsigned int&amp;, _generateRandomIndices(std::vector&lt;unsigned int&gt;&amp;, const unsigned int&amp;)::&lt;lambda()&gt;)'
  </code></pre>
  
  <p>What is the right way to use a lambda expression in this case ?</p>