title: C++: Constructor accepting only a string literal
body: <p>Is it possible to create a constructor (or function signature, for that matter) that <em>only</em> accepts a string literal, but not an e.g. <code>char const *</code>?</p>
  
  <p>Is it possible to have two overloads that can distinguish between string literals and <code>char const *</code>?</p>
  
  <p>C++ 0x would kind-of allow this with a custom suffix - but I'm looking for an "earlier" solution.</p>
  
  <p><strong>Rationale:</strong> avoiding heap copy of strings that won't be modified when given as string literals. </p>
  
  <p>These strings directly go to an API expecting a <code>const char *</code> without any processing. Most calls do use literals requiring no additional processing, only in a few cases they are constructed.  I am looking for a possibility to preserve the native call behavior.</p>
  
  <p><strong>Note:</strong> - since it comes up in the answers: the code in question does not use <code>std::string</code> at all, but a good example would be:</p>
  
  <pre><code>class foo
  {
     std::string m_str;
     char const * m_cstr;      
   public:
     foo(&lt;string literal&gt; s) : m_cstr(p) {}
     foo(char const * s) : m_str(s) { m_cstr = s.c_str(); }
     foo(std::string const &amp; s) : m_str(s) { m_cstr = s.c_str(); }
  
     operator char const *() const { return m_cstr; }
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Results:</strong>  </p>
  
  <p>(1) it can't be done.<br>
  (2) I realized I am not even looking for a literal, but for a compile-time-constant (i.e. "anything that needs not be copied").</p>
  
  <p>I will probably use the following pattern instead:</p>
  
  <pre><code>const literal str_Ophelia = "Ophelia";
  
  void Foo()
  {
    Hamlet(str_Ophelia, ...);  // can receive literal or string or const char *
  }
  </code></pre>
  
  <p>with a simple</p>
  
  <pre><code>struct literal  
  { 
     char const * data; 
     literal(char const * p) : data(p) {} 
     operator const char *() const { return data; }
  };
  </code></pre>
  
  <p>That doesn't stop anyone from abusing it (I should find a better name...), but it allows the required optimization but remains safe by default.</p>