title: Default value for function argument which is pointer to member
body: <p>I'm trying to implement decorator for functions using variadic templates. And try to minimize number of overloads since it reduce the size of a compiler error messages in case of template params deducion failure. I have implementation which works with any member of any class (works with delegate Ret (Ctx::*member)(Args...)) and one extra overload which do not take pointer to member function and just calls first version passing &amp;Ctx::opeator(). I've tried to remove extra overload by adding default value for member pointer argument here. Here is the version which compiles:</p>
  
  <pre><code>template&lt;
      typename Decorator,
      typename Ctx, typename R, typename... Args,
      typename... CTorArgs
  &gt;
  Decorator decorate(
      CTorArgs&amp;&amp;...cargs,
      const Ctx &amp;obj, R (Ctx::*member)(Args...) const = &amp;Ctx::operator()
  ) {
      return Decorator(
          std::function&lt;R(Args...)&gt;([&amp;obj, member](Args... args){
              return (obj.*member)(args...);
          }),
          std::forward(cargs)...
      );
  }
  </code></pre>
  
  <p>But it can't be called without explicit member function specification. Here is an example I'm playing with right now:</p>
  
  <pre><code>struct IntDecorator {
      IntDecorator(std::function&lt;std::string(std::string)&gt; func): 
          m_func(func) {}
  
      std::string operator() (int val) {
          std::ostringstream oss;
          oss &lt;&lt; val;
          return m_func(oss.str());
      }
  private:
      std::function&lt;std::string(std::string)&gt; m_func;
  };
  
  struct PrefixAdder {
      PrefixAdder(std::string prefix): m_prefix(prefix) {}
      std::string addPrefix(std::string val) const {return m_prefix + val;}
      std::string operator() (std::string val) const {return m_prefix + val;}
  private:
      std::string m_prefix;
  };
  
  int main(int, char**) {
      PrefixAdder p("+++&gt; ");
      std::cout &lt;&lt; decorate&lt;IntDecorator&gt;(p, &amp;PrefixAdder::addPrefix)(123) &lt;&lt; std::endl;
      std::cout &lt;&lt; decorate&lt;IntDecorator&gt;(p, &amp;PrefixAdder::operator())(123) &lt;&lt; std::endl;
      std::cout &lt;&lt; decorate&lt;IntDecorator&gt;(p)(123) &lt;&lt; std::endl; // compilation error
  }
  </code></pre>
  
  <p>compiler can't deduce type R (member function return type). The code works after adding extra overload which I try to elliminate or by specifying all template parameters which is even worse than extra overload:</p>
  
  <pre><code>template&lt;typename Decorator, typename Ctx, typename... CTorArgs&gt;
  Decorator decorate(CTorArgs&amp;&amp;...cargs, const Ctx &amp;obj) {
      return decorate&lt;Decorator&gt;(cargs..., obj, &amp;Ctx::operator());
  }
  </code></pre>
  
  <p>Can I have automatic type dedution without additional version of decorate template? What is the problem to deduce types automatically here in C++11?</p>
  
  <p><strong>Edit:</strong> My initial aim was to have better error message and I've achieved it using type traits and static_assert. So this question is more theoretical then practical for now. If somebody knows how to write one implementation which covers delegate and functor you can provide an answer and I'll accept it.</p>