title: Is it possible to prevent "copy and paste similar template special case" for this code?
body: <p>I have some program which reads vector recursively like this:</p>
  
  <pre><code>#define ARRAYTOJSON(x) arrayToJson&lt;decltype(x)&gt;(#x,x)
  template&lt;class V&gt;
  inline void arrayToJson(const char* c,V&amp; v){
      typedef typename V::value_type E;
      for(typename std::vector&lt;E&gt;::iterator it=v.begin();it!=v.end();++it){
          arrayToJson(c,*it);
      }
  }
  
  template&lt;&gt;
  inline void arrayToJson(const char* c,int&amp; v){
      printf("%s %d\n",c,v);
  }
  
  int main(){
      std::vector&lt;int&gt; v;
      v.push_back(5);
      ARRAYTOJSON(v);
  
      int i=0;
      ARRAYTOJSON(i);
      return 0;
  }
  </code></pre>
  
  <p>but now I want to add special cases for 2 new class with a test() method:</p>
  
  <pre><code>class A{
  public:
      void test(){}
  };
  
  class B{
  public:
      void test(){}
  }; 
  </code></pre>
  
  <p>what I need to do now is to copy the special case and place it in code:</p>
  
  <pre><code>template&lt;&gt;
  inline void arrayToJson(const char* c,A&amp; v){
      v.test();
  }
  
  template&lt;&gt;
  inline void arrayToJson(const char* c,B&amp; v){
      v.test();
  }
  </code></pre>
  
  <p>is there any syntax that force the special case (if no other special case can be used) to use generic template special case like:</p>
  
  <pre><code>template&lt;&gt;
  inline void arrayToJson(const char* c,B&amp; v){
      v.test();
  }
  </code></pre>
  
  <p>so that I no need to copy and place each special case for each class?</p>