title: Binding generic callbacks with arguments c++11
body: <p>I have a class called Renderer that holds two callback objects;</p>
  
  <pre><code>void (*drawCall)(const sf::Drawable&amp; drawable, const sf::RenderStates&amp; states);
  void (*drawPrimCall)(const sf::Vertex* vertices, unsigned int vertexCount,
      sf::PrimitiveType type, const sf::RenderStates&amp; states);
  </code></pre>
  
  <p>I would like to have a public function that binds these callbacks, it's templated and needs a class that has two draw methods each with their valid parameters, something like this:</p>
  
  <pre><code>template&lt;typename T&gt;
  inline void setRenderer(T* instance)
  {
      using namespace std::placeholders;
      drawCall = std::bind(&amp;T::draw, instance, _1, _2);
      drawPrimCall = std::bind(&amp;T::draw, instance, _1, _2, _3, _4);
  }
  </code></pre>
  
  <p>However, as you might imagine this does not work. I'm still learning about std::bind and I'm not sure about the use of placeholders, it's understood what I'm trying to do here.</p>
  
  <p>I've tried looking for answers in Google but it has been a bit daunting, thanks for any help!</p>
  
  <p>UPDATE:</p>
  
  <p>Ok, so the answer given by @Holt works, after changing to std::function my callbacks look like this:</p>
  
  <pre><code>std::function&lt;void(const sf::Drawable&amp; drawable, const sf::RenderStates&amp; states)&gt; drawCall_fn;
  std::function&lt;void(const sf::Vertex* vertices, unsigned int vertexCount,
                     sf::PrimitiveType type, const sf::RenderStates&amp; states)&gt; drawPrimCall_fn;
  </code></pre>
  
  <p>Now for the setRenderer method due to constraints on external libraries I also need to pass a function reference, like so;</p>
  
  <pre><code>template&lt;typename T&gt;
  inline void setRenderer(T* instance, void(T::*drawCall)(const sf::Drawable&amp;, const sf::RenderStates&amp;))
  {
      using namespace std::placeholders;
      drawCall_fn = std::bind(drawCall, instance, _1, _2);
  }
  </code></pre>
  
  <p>Such that when called I can do it like this:</p>
  
  <pre><code>renderer.setRenderer&lt;sf::RenderTarget&gt;(&amp;window, &amp;sf::RenderTarget::draw);
  </code></pre>
  
  <p>**Note: I'm only dealing with drawCall_fn for the moment as I can easily expand after.</p>
  
  <p>UPDATE2: Added missing parameters for setRenderer drawCall.</p>