title: Overload char pointers and string literals
body: <p>I'm trying to create a class that will accept (and can disambiguate) string literals from char pointers. When searching this problem the solution provided was to create a 'holder' class that only accepts char pointers:</p>
  
  <pre><code>template&lt; typename char_t &gt;
  class String
  {
      struct holder_t
      {
          const char_t* s;
          holder_t( const char_t* s ) : s(s) {}
          holder_t( char_t* s ) : s(s) {}
      };
  public:
  
      // Construct from string literal
      template&lt; size_t S &gt;
      String( const char_t (&amp;str)[S] )
      {
          std::cout &lt;&lt; "String Literal: " &lt;&lt; str;
      }
  
      // Construct from char pointer
      String( holder_t h )
      {
          std::cout &lt;&lt; "Char Pointer: " &lt;&lt; h.s;
      }
  };
  </code></pre>
  
  <p>The big idea is that you should never have to explicitly create instances of this class, it should happen by implicit conversion:</p>
  
  <pre><code>void StringFoo( String&lt;char&gt; s )
  {
  }
  </code></pre>
  
  <p>However this results in compile errors for char pointers, <em>why isn't the implicit conversion working?</em></p>
  
  <pre><code>int main()
  {
      // Works!
      StringFoo( "literal" );
  
      // error C2664: 'StringFoo' : cannot convert parameter 1 from 'const char *' to 'String&lt;char_t&gt;'
      // with [ char_t=char ]
      // No constructor could take the source type, or constructor overload resolution was ambiguous
      StringFoo( (const char*)"const char ptr" );
  
      // Works!
      StringFoo( String&lt;char&gt;((const char*)"const char ptr") );
  
      // error C2664: 'StringFoo' : cannot convert parameter 1 from 'char *' to 'String&lt;char_t&gt;'
      // with [ char_t=char ]
      // No constructor could take the source type, or constructor overload resolution was ambiguous
      StringFoo( (char*)"char ptr" );
  
      // Works!
      StringFoo( String&lt;char&gt;((char*)"const char ptr") );
  
      return 0;
  }
  </code></pre>
  
  <p>This is just a simple pointless example; in my real code I created a class that will hold the hash of the string.</p>
  
  <p>The hash should be generated at compile time if a string literal is passed and calculated at runtime if a char pointer is passed.</p>
  
  <p>However this should be completely transparent to the user who just passes strings around, hashing is done automagically.</p>