title: Use template to apply a function template
body: <p>If the following example were C++ it would contain non-sensical gibberish so I'll define the example to be written in pseudocode (and hence correct). It strongly hints at what I want to do in C++.</p>
  
  <pre><code>#include &lt;vector&gt;
  
  template&lt;class T&gt;
  void increment(T&amp; x)
  {
      ++x;
  }
  
  template&lt;template&lt;class&gt; class F&gt;
  struct Apply
  {
      template&lt;class T&gt;
      void operator()(std::vector&lt;T&gt;&amp; v)
      {
          for (auto&amp; x : v)
              F&lt;T&gt;(x);
      }
  };
  
  template&lt;template&lt;class&gt; class F, class T&gt;
  void apply(F&lt;T&gt; f, std::vector&lt;T&gt;&amp; v)
  {
      for (auto&amp; x : v)
          f(x);
  }
  
  int main()
  {
      std::vector&lt;int&gt; v{1,2,3};
  
      // apply increment function to v
  
      // maybe this?
      Apply&lt;increment&gt; a;
      a(v);
  
      // hmm... or this?
      apply(increment, v);
  }
  </code></pre>
  
  <p>I don't know how to turn this into C++ such that:</p>
  
  <ol>
  <li><p><code>increment</code> is a function and not a function object.</p></li>
  <li><p>The parameter of <code>increment</code> is either deduced or supplied by <code>Apply</code>/<code>apply</code>.</p></li>
  <li><p><code>Apply</code>/<code>apply</code> does not know about the name <code>increment</code>.</p></li>
  </ol>
  
  <p>I can satisfy two out of the three but I'm not sure how to satisfy all three at once. The problem I run into is the apparent need for using a function template as a template template parameter which my compiler doesn't like. Still, it certainly seems possible to get this to work even if that particular route is off limits.</p>
  
  <p>How can it be done?</p>
  
  <p><strong>Edit:</strong> I hate to change the problem but I didn't do a great job of trying to formally state requirements. Just pretend you're the author of apply but you're not the author of <code>increment</code>. You're stuck with <code>increment</code> as is.</p>