title: Is there a way to explicitly specify template parameters when invoking a boost::bind object?
body: <p>I'm trying to create a generic dispatch function to a specific instantiation of a template functor. I have a common pattern in some of my work that looks something like this:</p>
  
  <pre><code>// func is some template function
  char f;
  if (f == 'B') return func&lt;int8_t&gt;();
  else if (f == 'I') return func&lt;int16_t&gt;();
  else if (f == 'L') return func&lt;int32_t&gt;();
  // and so on
  </code></pre>
  
  <p>I would like to wrap up this common logic into a reusable library that will invoke a given function using a particular template argument based upon a runtime value. I don't know of a good way to generically do that using function pointers (since you can't have a pointer to a template), but I came up with the following to work with a generic functor type <code>Func</code>:</p>
  
  <pre><code>template &lt;typename Func&gt;
  void format_dispatch(Func func, char f)
  {
      if (f == 'B') func.template operator()&lt;int8_t&gt;();
      else if (f == 'I') func.template operator()&lt;int16_t&gt;();
      else if (f == 'L') func.template operator()&lt;int32_t&gt;();
  }
  </code></pre>
  
  <p>As long as <code>Func</code> has an <code>operator()</code> that takes a single template type argument, I would like the above to work, and it does, like with the following example:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdint.h&gt;
  #include &lt;typeinfo&gt;
  
  template &lt;typename Func&gt;
  void format_dispatch(Func func, char f)
  {
      if (f == 'B') func.template operator()&lt;int8_t&gt;();
      else if (f == 'I') func.template operator()&lt;int16_t&gt;();
      else if (f == 'L') func.template operator()&lt;int32_t&gt;();
  }
  
  struct foo
  {
      template &lt;typename T&gt;
      void operator()() const
      {
          std::cout &lt;&lt; typeid(T).name() &lt;&lt; std::endl;
      }
  };
  
  int main()
  {
      format_dispatch(foo(), 'B');
      format_dispatch(foo(), 'I');
  }
  </code></pre>
  
  <p>This is a bit limiting though. I would like to be able to pass bind expressions to handle the case where the functor's call operator takes some arguments, something like:</p>
  
  <pre><code>int x;
  format_dispatch(boost::bind&lt;void&gt;(foo(), x));
  </code></pre>
  
  <p>However, this doesn't work, because it doesn't look like the underlying <code>bind_t</code> type supports explicit specification of template arguments to its call operator. Is there any way to accomplish the interface that I'm looking for? For this application, I'm not able to take advantage of C++11; it has to be C++03 only.</p>