title: C++ sequence generator with init value by function enclosure
body: <p>I have a question: Is below piece of code valid and whether it is optimum for sequence generator function in C++14?</p>
  
  <pre><code>auto sequenceGen = [](int&amp;&amp; init) {
      int counter = init;
      return [counter=std::move(counter)]() mutable { return ++counter; };
  };
  auto getSeq1 = sequenceGen(100);
  cout &lt;&lt; getSeq1()&lt;&lt; endl;
  cout &lt;&lt; getSeq1()&lt;&lt; endl;
  </code></pre>
  
  <p>If not how should it be implemented? </p>