title: How to pass std::function with different parameters to same function
body: <p>I have three functions I'm looking to merge together.</p>
  
  <p>Each one takes an <code>std::function</code> as the first parameter, then executes it within a <code>try</code>/<code>catch</code> block.</p>
  
  <p>The issue is, there are three different types of functions. Functions with no parameters, those with one integer parameter, and those with two integer parameters. The ones with integer parameters also have their corresponding parameters passed through the original function.</p>
  
  <p>As one can see, each of the functions are nearly identical, so it would be nice if I could merge them all together. However, I'm unsure of anyway to setup a parameter that can receive any form of <code>std::function</code> and also rely on the fact it has been provided with corresponding data to use.</p>
  
  <p>Here are the functions:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>void run_callback(std::function&lt;void()&gt;&amp; func) {
      try {
          func();
      } catch(const std::exception&amp; ex) {
          print_callback_error(ex.what());
      } catch(const std::string&amp; ex) {
          print_callback_error(ex.c_str());
      } catch(...) {
          print_callback_error();
      }
  }
  
  void run_callback_int(std::function&lt;void(int)&gt;&amp; func, int data) {
      try {
          func(data);
      } catch(const std::exception&amp; ex) {
          print_callback_error(ex.what());
      } catch(const std::string&amp; ex) {
          print_callback_error(ex.c_str());
      } catch(...) {
          print_callback_error();
      }
  }
  
  void run_callback_intint(std::function&lt;void(int, int)&gt;&amp; func, int data1, int data2) {
      try {
          func(data1, data2);
      } catch(const std::exception&amp; ex) {
          print_callback_error(ex.what());
      } catch(const std::string&amp; ex) {
          print_callback_error(ex.c_str());
      } catch(...) {
          print_callback_error();
      }
  }
  </code></pre>
  
  <p>Any suggestions would be greatly appreciated!</p>