title: Class method specialisation with different signature
body: <p>I'm trying to write a class-template where the method signatures change depending on the template parameters. My goal is to have as little code duplication as possible. Consider this example, first the class declaration:</p>
  
  <pre><code>// a.hxx
  #ifndef A_HXX
  #define A_HXX
  
  template&lt;typename T&gt;
  struct A
  {
      void foo(T value) const;
      void bar() const;
  };
  
  #include &lt;string&gt;
  
  #ifndef short_declaration
  template&lt;&gt;
  struct A&lt;std::string&gt;
  {
      void foo(const std::string &amp;value) const;
      void bar() const;
  };
  #else // short_declaration
  template&lt;&gt;
  struct A&lt;std::string&gt;
  {
      void foo(const std::string &amp;value) const;
  };
  #endif // short_declaration
  
  #endif // A_HXX
  </code></pre>
  
  <p>Now the class definition:</p>
  
  <pre><code>// a_impl.hxx
  #ifndef A_IMPL_HXX
  #define A_IMPL_HXX
  
  #include "a.hxx"
  #include &lt;iostream&gt;
  #include &lt;typeinfo&gt;
  
  template&lt;typename T&gt;
  void A&lt;T&gt;::foo(T value) const
  {
      std::cout &lt;&lt; "A&lt;T=" &lt;&lt; typeid(T).name() &lt;&lt; "&gt;::foo(" &lt;&lt; value &lt;&lt; ")"
          &lt;&lt; std::endl;
  }
  
  template&lt;typename T&gt;
  void A&lt;T&gt;::bar() const
  {
      std::cout &lt;&lt; "A&lt;T=" &lt;&lt; typeid(T).name() &lt;&lt; "&gt;::bar()" &lt;&lt; std::endl;
  }
  
  void A&lt;std::string&gt;::foo(const std::string &amp;value) const
  {
      std::cout &lt;&lt; "A&lt;std::string&gt;::foo(" &lt;&lt; value &lt;&lt; ")" &lt;&lt; std::endl;
  }
  
  #ifndef skip_duplicates
  void A&lt;std::string&gt;::bar() const
  {
      std::cout &lt;&lt; "A&lt;std::string&gt;::bar()" &lt;&lt; std::endl;
  }
  #endif // skip_duplicates
  
  #endif // A_IMPL_HXX
  </code></pre>
  
  <p>And now a test program:</p>
  
  <pre><code>// test.cxx
  
  //#define skip_duplicates
  //#define short_declaration
  #include "a_impl.hxx"
  
  int main(void)
  {
      A&lt;int&gt;         obj1;
      A&lt;std::string&gt; obj2;
      int         value1(1);
      std::string value2("baz");
  
      obj1.foo(value1);
      obj1.bar();
  
      obj2.foo(value2);
      obj2.bar();
  
      return 0;
  }
  </code></pre>
  
  <p>If compiled like this, I get the expected output of (for my implementation of typeid):</p>
  
  <pre><code>A&lt;T=i&gt;::foo(1)
  A&lt;T=i&gt;::bar()
  A&lt;std::string&gt;::foo(baz)
  A&lt;std::string&gt;::bar()
  </code></pre>
  
  <p>But I would of course like a way to enable either <code>skip_duplicates</code> or even <code>short_declaration</code> in my example. To a somewhat <a href="https://stackoverflow.com/questions/11454389/function-specialisation-with-different-signature">similar question</a>, <a href="https://stackoverflow.com/users/567292/ecatmur">ecatmur</a> replied that the full class needs to be given, so at least defining <code>short_declaration</code> would not work.</p>
  
  <p>How do others handle the problem of creating class templates with methods that may take large objects as arguments?</p>