title: c++ template C-string parameter
body: <p>I was working on a template for a function. To simplify, say it looks like this:</p>
  
  <pre><code>template &lt; typename T &gt;
  void f(const T &amp; x)
  {
      cout &lt;&lt; "generic case" &lt;&lt; endl;
      cout &lt;&lt; x &lt;&lt; endl;
  }
  </code></pre>
  
  <p>I always thought that C-strings cannot be used as template parameter arguments. But the following actually works (using g++ 4.5.1):</p>
  
  <pre><code>f("hello world");
  </code></pre>
  
  <p>So my question is: what is <code>T</code> when I call <code>f("hello world")</code>? </p>
  
  <p>I tried to specialize to see what exactly is happening. For instance since <code>char[]</code> is <code>const char*</code> I looked at this (which obviously does not work):</p>
  
  <pre><code>template &lt; typename T &gt;
  void f(const T &amp; x)
  {
      cout &lt;&lt; "generic case" &lt;&lt; endl;
      cout &lt;&lt; x &lt;&lt; endl;
  }
  template &lt;&gt;
  void f(const const char * T &amp; x)
  {
      cout &lt;&lt; "char[] case" &lt;&lt; endl;
      cout &lt;&lt; x &lt;&lt; endl;
  }
  </code></pre>
  
  <p>and tried several variations. None of them work.</p>
  
  <p>ASIDE: I don't really need this for what I'm doing. I need a specialization for the case of T = "C-string" so I just wrote another template function:</p>
  
  <pre><code>template &lt; typename T &gt;
  void f(const T &amp; x)
  {
      cout &lt;&lt; "generic case" &lt;&lt; endl;
      cout &lt;&lt; x &lt;&lt; endl;
  }
  template &lt; typename T &gt;
  void f(T x[])
  {
      cout &lt;&lt; "T[] case" &lt;&lt; endl;
      cout &lt;&lt; x &lt;&lt; endl;
  }
  </code></pre>
  
  <p>I'm just asking because I'm curious as to what exactly is happening and why is a C-string allowed to be a template argument when what I've read said that it <em>can't</em> be. I must have misread/misunderstood something about templates.</p>