title: Alternative to std::function for passing function as argument (callbacks, etc.)
body: <p>I stumbled across this during my experiments with C++11. I find that it is an obvious solution, but I haven't been able to find any other examples of it in the wild, so I'm concerned that there's something I'm missing. </p>
  
  <p>The practice I'm referring to (in the "addAsync" function):</p>
  
  <pre><code>#include &lt;thread&gt;
  #include &lt;future&gt;
  #include &lt;iostream&gt;
  #include &lt;chrono&gt;
  
  int addTwoNumbers(int a, int b) {
      std::cout &lt;&lt; "Thread ID: " &lt;&lt; std::this_thread::get_id() &lt;&lt; std::endl;
  
      return a + b;
  }
  
  void printNum(std::future&lt;int&gt; future) {
      std::cout &lt;&lt; future.get() &lt;&lt; std::endl;
  }
  
  void addAsync(int a, int b, auto callback(std::future&lt;int&gt;) -&gt; void) { //&lt;- the notation in question
      auto res = std::async(std::launch::async, addTwoNumbers, a, b);
  
      if (callback) //super straightforward nullptr handling
          return callback(std::move(res));
  }
  
  int main(int argc, char** argv) {
      addAsync(10, 10, [](std::future&lt;int&gt; number) { //lambda functions work great
          addAsync(number.get(), 20, [](std::future&lt;int&gt; number) {
              addAsync(893, 4387, printNum); //as do standard functions
              addAsync(2342, 342, nullptr); //executes, sans callback
  
              std::cout &lt;&lt; number.get() &lt;&lt; std::endl;
          });
      });
  
      std::cout &lt;&lt; "main thread: " &lt;&lt; std::this_thread::get_id() &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>
  
  <p>Is it considered bad practice, or is it non-portable (I've only tried it in MSVC++ 2015)? Also, how does the compiler treat this; by conversion to std::function? </p>
  
  <p>I would love to keep using this in my projects, as it obviously states the required argument types and return type in the "signature", accepts a nullptr for optionality, and seems to "just work" (I am aware that these are famous last words in C++).</p>