title: How to implement an easy_bind() that automagically inserts implied placeholders? *With member pointers*
body: <p>I have come upon this interesting solution (<a href="https://stackoverflow.com/a/15025170/3167362">here</a> with an example <a href="http://liveworkspace.org/code/3CIkx" rel="nofollow noreferrer">here</a>) to make a std::bind type function without having to explicitly put placeholders. </p>
  
  <h2>Quest</h2>
  
  <p>To implement a similar bind function without the capability to put values in the bind call (I don't need it.) and to add the capability to call this new bind function to bind a member pointer.</p>
  
  <h2>What I managed to do</h2>
  
  <p>So I figured out how to use a dummy std::function to get the function's signature.<br>
  I also figured out how to remove the capability of adding values to the bins call.  </p>
  
  <p>So here is the code I have:</p>
  
  <pre><code>#include &lt;functional&gt;
  #include &lt;type_traits&gt;
  #include &lt;utility&gt;
  
  template &lt;std::size_t... Is&gt;
  struct indices {};
  
  template &lt;std::size_t N, std::size_t... Is&gt;
  struct build_indices
    : build_indices&lt;N-1, N-1, Is...&gt; {};
  
  template &lt;std::size_t... Is&gt;
  struct build_indices&lt;0, Is...&gt; : indices&lt;Is...&gt; {};
  
  template&lt;int I&gt; struct placeholder{};
  
  namespace std{
  template&lt;int I&gt;
  struct is_placeholder&lt; ::placeholder&lt;I&gt;&gt; : std::integral_constant&lt;int, I&gt;{};
  } // std::
  namespace detail{
      template&lt;std::size_t... Is, class Fn, class... Args&gt;
      auto my_bind(indices&lt;Is...&gt;, Fn const &amp;f, Fn *i, Args&amp;&amp;... args) 
          -&gt; decltype(std::bind(f, &amp;i, std::forward&lt;Args&gt;(args)..., placeholder&lt;1 + Is&gt;{}...)){
          return std::bind(f, &amp;i, std::forward&lt;Args&gt;(args)..., placeholder&lt;1 + Is&gt;{}...);
      }
  }
  
  template&lt;class Ret, class... FArgs, class Fn, class... Args&gt;
  auto my_bind(std::function&lt;Ret(FArgs...)&gt;, Fn const&amp;f, Fn *i, Args&amp;&amp;... args) 
          -&gt; decltype(detail::my_bind(build_indices&lt;sizeof...(FArgs) - sizeof...(Args)&gt;{}, f, &amp;i, std::forward&lt;Args&gt;(args)...)){
  
      return detail::my_bind(build_indices&lt;sizeof...(FArgs) - sizeof...(Args)&gt;{}, f, &amp;i, std::forward&lt;Args&gt;(args)...);
  }
  
  
  #include &lt;iostream&gt;
  struct tmp{
      void testt(int var1, int var2){
          std::cout &lt;&lt; var1 &lt;&lt; " " &lt;&lt; var2 &lt;&lt; std::endl;
      }
  };
  
  int main(){
  
      tmp TMP;
      auto f3 = my_bind(std::function&lt;void(int, int)&gt;(), &amp;tmp::testt, &amp;TMP);
      f3(22, 23);
  
  }  
  </code></pre>
  
  <h2>Problem</h2>
  
  <p>I tried to pass the member pointer to the template however I'm getting compiler errors. (The problem seems related to the passing of the member pointer) I tried other methods of passing a member pointer such as depicted <a href="https://stackoverflow.com/questions/7857518/c-passing-a-pointer-into-a-template">here</a> and <a href="http://timmurphy.org/2014/08/28/passing-member-functions-as-template-parameters-in-c/" rel="nofollow noreferrer">here</a> however I have not gained any progress using these methods.  </p>
  
  <p>Here are the errors:</p>
  
  <pre><code>g++ -std=c++11 -Wall -W -pedantic -O2 hello-cpp-world.cc -o hello-cpp-world
  hello-cpp-world.cc: In function ‘int main()’:
  hello-cpp-world.cc:68:73: error: no matching function for call to ‘my_bind(std::function&lt;void(int, int)&gt;, void (tmp::*)(int, int), tmp*)’
       auto f3 = my_bind(std::function&lt;void(int, int)&gt;(), &amp;tmp::testt, &amp;TMP);
                                                                           ^
  hello-cpp-world.cc:68:73: note: candidate is:
  hello-cpp-world.cc:48:6: note: template&lt;class Ret, class ... FArgs, class Fn, class ... Args&gt; decltype (detail::my_bind(build_indices&lt;(sizeof (FArgs ...) - sizeof (Args ...))&gt;{}, f, (&amp; i), (forward&lt;Args&gt;)(my_bind::args)...)) my_bind(std::function&lt;_Res(_ArgTypes ...)&gt;, const Fn&amp;, Fn*, Args&amp;&amp; ...)
   auto my_bind(std::function&lt;Ret(FArgs...)&gt;, Fn const&amp;f, Fn *i, Args&amp;&amp;... args) -&gt; decltype(detail::my_bind(build_indices&lt;sizeof...(FArgs) - sizeof...(Args)&gt;{}, f, &amp;i, std::forward&lt;Args&gt;(args)...)){
        ^
  hello-cpp-world.cc:48:6: note:   template argument deduction/substitution failed:
  hello-cpp-world.cc:68:73: note:   deduced conflicting types for parameter ‘Fn’ (‘void (tmp::*)(int, int)’ and ‘tmp’)
       auto f3 = my_bind(std::function&lt;void(int, int)&gt;(), &amp;tmp::testt, &amp;TMP);
                                                                           ^
  make: *** [hello-cpp-world] Error 1
  </code></pre>
  
  <h2>Question</h2>
  
  <ul>
  <li>Is what I am trying to achieve even possible? (Although I am quite certain it is) </li>
  <li>If so, how can this be fixed?</li>
  </ul>