title: Is there a generic way to adapt a function template to be a polymorphic function object?
body: <p>I have some function templates, for example</p>
  
  <pre><code>template &lt;typename T&gt;
  void foo(T);
  
  template &lt;typename T&gt;
  void bar(T);
  
  // others
  </code></pre>
  
  <p>and I need to pass each one to an algorithm that will call it with various types, e.g.</p>
  
  <pre><code>template &lt;typename F&gt;
  void some_algorithm(F f)
  {
      // call f with argument of type int
      // call f with argument of type SomeClass
      // etc.
  }
  </code></pre>
  
  <p>I can't pass in my function template uninstantiated, but I can't instantiate it with any specific type either because <code>some_algorithm</code> will need to call it with arguments of several different types.</p>
  
  <p>I could adapt my function templates to be polymorphic function objects, e.g.</p>
  
  <pre><code>struct foo_polymorphic
  {
      template &lt;typename T&gt;
      void operator()(T t)
      {
          foo(t);
      }
  };
  </code></pre>
  
  <p>and then pass it as <code>some_algorithm(foo_polymorphic())</code>. But this requires writing a separate adapter for each of my function templates.</p>
  
  <p>Is there a <strong>generic</strong> way of adapting a function template to be a polymorphic function object, i.e. some mechanism that I can re-use for each of the function templates I need to adapt, without having to declare something separately for each one?</p>