Is it possible to base the template specialization on the presence or absence of a certain argument in the method signature?
<p>Consider the following class:</p>

<pre><code>class MyClass
{
public:
  template&lt;class T&gt; typename T::result_type apply(T&amp; func)
  {
    if (is_int())
    {
      return func(int(0));
    }
    return func(double(0));
  }
  ...
};
</code></pre>

<p>(The code does not look terribly useful, but it is only a contrived sample to demonstrate my point)</p>

<p>Anyway, a typical functor would be something like this:</p>

<pre><code>struct MyFunc
{
  typedef void result_type;
  template&lt;class V&gt; void operator()(V)
  {
    // do something
  }
};
</code></pre>

<p>And one would use it like so:</p>

<pre><code>MyClass c;
MyFunc f;
c.apply(f);
</code></pre>

<p>My question is this - can <code>MyClass::apply</code> be changed to recognize a slightly different version of the functor <strong>in addition to the original one</strong>, for instance the one expecting the caller object reference to be passed along with all the other parameters, something like this:</p>

<pre><code>struct MyFuncEx
{
  typedef void result_type;
  template&lt;class V&gt; void operator()(const MyClass&amp; caller, V)
  {
    // do something
  }
};
</code></pre>

<p>So, the following code would compile too:</p>

<pre><code>MyClass c;
MyFunc f;
c.apply(f);
MyFuncEx f2;
c.apply(f2);
</code></pre>

<p>As a bonus I would like the compilation to fail if the functor contains both overloads, i.e. the following should fail the compilation:</p>

<pre><code>struct MyFuncSmartAss
{
  typedef void result_type;
  template&lt;class V&gt; void operator()(V)
  {
    // do something
  }
  template&lt;class V&gt; void operator()(const MyClass&amp; caller, V)
  {
    // do something
  }
};

...

MyClass c;
c.apply(MyFuncSmartAss());
</code></pre>

<p>But, it is not that important as long as the longer overload takes the precedence over the shorter one.</p>
