title: how to specialize template function to let it accept passing a char array as argument?
body: <pre><code>// problem.cpp:
  #include &lt;string&gt;
  
  template&lt;typename T&gt; void func(const T &amp; v);
  
  int main() {
          int i;
          float f;
          char * cp;
          char ca[4];
  
          func(i);
          func(f);
          func(cp);
          func(std::string("std::string"));
          func(ca);
          func("string_literal");
  
          return 0;
  }
  
  // problem2.cpp
  #include &lt;string&gt;
  
  template&lt;typename T&gt; void func(const T &amp; v);
  
  // undefined reference to `void func&lt;int&gt;(int const&amp;)'
  template&lt;&gt; void func&lt;int&gt;(const int &amp; v) { }
  
  // undefined reference to `void func&lt;float&gt;(float const&amp;)'
  template&lt;&gt; void func&lt;float&gt;(const float &amp; v) { }
  
  // undefined reference to `void func&lt;char*&gt;(char* const&amp;)'
  template&lt;&gt; void func&lt;char *&gt;(char * const &amp; v) { }
  
  // void func&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;(std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)
  template&lt;&gt; void func&lt;std::string&gt;(std::string const &amp; v) { }
  
  // undefined reference to `void func&lt;char [4]&gt;(char const (&amp;) [4])'
  // ???
  
  // undefined reference to `void func&lt;char [15]&gt;(char const (&amp;) [15])'
  // ???
  </code></pre>
  
  <p>Found two solutions:</p>
  
  <p>a) in problem2.cpp:</p>
  
  <pre><code>template&lt;&gt; void func&lt;char[4]&gt;(const char (&amp;v)[4]) { }
  template&lt;&gt; void func&lt;char[15]&gt;(const char (&amp;v)[15]) { }
  </code></pre>
  
  <p>b) in problem.cpp:</p>
  
  <pre><code>template&lt;typename T, unsigned N&gt; void func(const T (&amp;v)[N]) { func(v+0); }
  and then in problem2.cpp, add the newly missing
  template&lt;&gt; void func&lt;const char *&gt;(const char * const &amp; v) { }
  </code></pre>
  
  <p>Sorry akappa, had to edit again to clarify that they are two independant solutions ...</p>
  
  <p>akappa: My only way to add something to this question is by editing it. Neither can I comment nor can I add an answer. May have something to do with »Stack Overflow requires external JavaScript from another domain, which is blocked or failed to load.« which I don't know how to resolve because I don't know that exactly SO is trying to tell me there.</p>