title: C++ lambda capture woes
body: <p>The following code fails to compile (both GCC and clang say the lambda isn't a proper function?)</p>
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  void apply(void f(int)) {
      f(10);
      f(20);
      f(30);
  }
  
  int main()
  {
      int col = 42;
  
      apply([col](int data) -&gt; void {
                    cout &lt;&lt; data &lt;&lt; ' ' &lt;&lt; col &lt;&lt; endl;
            });
  }
  </code></pre>
  <p>clang++ says:</p>
  <pre><code>fails.cc:5:6: note: candidate function not viable: no known conversion from '(lambda at       
  fails.cc:15:8)' to 'void (*)(int)' for 1st argument
  void apply(void f(int)) {
       ^
  1 error generated.
  </code></pre>
  <p>If you get rid of the <code>col</code> capture and it's use, it compiles and works fine. Rummaging in <a href="https://en.cppreference.com/w/cpp/language/lambda" rel="nofollow noreferrer">cppreference</a> just tells me everything is OK...</p>
  <p>What would be the point of lambdas if captures aren't allowed?</p>