title: Template Argument Deduction from String Literal
body: <p>I am currently thinking about how to best constrain a generic type of a template to an <code>std::sting</code> as well as string literals. Therefore I compare the deduced type with the desired type using <code>std::is_same</code>. In case of an <code>std::string</code> this works right away. For a string literal, meaning a char const array, it only works if I use <code>std::decay</code> on the type and then compare the result to the type <code>char const *</code>. If I directly compare the deduced type to what I think it should be, <code>is_same</code> returns false, as is illustrated by the following example code.</p>
  
  
  
  <pre class="lang-cpp prettyprint-override"><code>template &lt;class TYPE&gt;
  void function(TYPE&amp;&amp; parameter)
  {
    //this doesn't work as expected
    std::cout &lt;&lt; typeid(TYPE).name() &lt;&lt; " : " &lt;&lt; typeid(char const [5]).name() &lt;&lt; std::endl;
    std::cout &lt;&lt; std::is_same&lt;char const [5], TYPE&gt;::value &lt;&lt; std::endl;
    //this works as expected
    std::cout &lt;&lt; typeid(std::decay_t&lt;TYPE&gt;).name() &lt;&lt; " : " &lt;&lt; typeid(char const *).name() &lt;&lt; std::endl;
    std::cout &lt;&lt; std::is_same&lt;char const *, std::decay_t&lt;TYPE&gt;&gt;::value &lt;&lt; std::endl;
  }
  
  int main(int argc, char** argv)
  {
    function("name");
    return 0;
  }
  </code></pre>
  
  <p>The output generated is the following:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>char const [5] : char const [5]
  0
  char const * __ptr64 : char const * __ptr64
  1
  </code></pre>
  
  <p><strong>Now, what I am wondering is why <code>is_same</code> returns false in the first case even though the types appear to be identical.</strong></p>
  
  <p>The only possible explanation that I could come up with is that within the function <code>std::is_same</code> a transformation similar to <code>std::decay</code> is applied to the type (for instance a function call). But then again this transformation would also occur to the other type, yielding the same result and thus resulting in equality.</p>