title: std::function as sighandler_t
body: <p>How to specify lambda, std::bind result or any other std::function as argument for unix signal function?</p>
  
  <p>I'm trying the following</p>
  
  <pre><code>std::function&lt;void(int)&gt; handler1 = std::bind(&amp;cancellation_token::cancel, &amp;c);
  std::function&lt;void(int)&gt; handler2 = [&amp;c](int) { c.cancel(); };
  </code></pre>
  
  <p>but it doesn't work, because both</p>
  
  <pre><code>handler1.target&lt;void(int)&gt;()
  </code></pre>
  
  <p>and</p>
  
  <pre><code>handler2.target&lt;void(int)&gt;()
  </code></pre>
  
  <p><code>return null</code></p>
  
  <p>It works if I initialize handler with free function pointer</p>
  
  <pre><code>void foo(int) { ... }
  std::function&lt;void(int)&gt; handler = foo;
  </code></pre>
  
  <p>but this is absolutely useless. I need to capture some local variables, so I need either bind or lambda.</p>
  
  <p>Actually I understand why it doesn't work. Documentation says that <code>target</code> function returns a pointer to the stored function if <code>target_type() == typeid(T)</code>, otherwise a null pointer. I don't understand how to make it work.</p>
  
  <p>Any suggestions?</p>