title: Template specialization for char pointer?
body: <p><code>boost::lexical_cast</code> is a great tool but in my application I ran into a limitation in <code>string -&gt; bool</code> conversion that is bugging me. I need to convert all strings like <code>"0"</code>, <code>"false"</code> and <code>"FALSE"</code> into <code>false</code> and <code>"1"</code>, <code>"true"</code> and <code>"TRUE"</code> into <code>true</code>.</p>
  
  <p><code>boost::lexical_cast</code> only support conversion from/to <code>"0"</code> and <code>"1"</code>. So my idea was to write my own conversion function which seems to work fine:</p>
  
  <pre><code>bool str_to_bool(const std::string &amp;str)
  {
      if(str == "1" || str == "true" || str == "TRUE")
          return true;
      else if(str == "0" || str == "false" || str == "FALSE")
          return false;
      else
          throw std::runtime_error("Bad cast from std::string to bool!");
  }
  </code></pre>
  
  <p>Now I wan to write a wrapper round <code>boost::lexical_cast</code> and write my own template specializations for it. Here is what I've got so far:</p>
  
  <pre><code>template&lt;typename Target, typename Source&gt;
  inline Target my_cast(const Source&amp; src)
  {
      return boost::lexical_cast&lt;Target&gt;(src);
  }
  
  template&lt;&gt;
  inline bool my_cast(const std::string&amp; src)
  {
      return str_to_bool(src);
  }
  </code></pre>
  
  <p>This works great for integers or std::string but obviously fails for string literals or character pointers:</p>
  
  <pre><code>int main(int argc, char* argv[])
  {
      std::cout &lt;&lt; my_cast&lt;bool&gt;(1) &lt;&lt; std::endl;                    //OK
      std::cout &lt;&lt; my_cast&lt;bool&gt;(std::string("true")) &lt;&lt; std::endl;  //OK
      std::cout &lt;&lt; my_cast&lt;bool&gt;("true") &lt;&lt; std::endl;               //Fail! 
  
      return 0;
  }
  </code></pre>
  
  <p>So I tried to write another specialization for <code>char *</code> but it fails to compile!</p>
  
  <pre><code>//does not compile!
  template&lt;&gt;
  inline bool my_cast(const char*&amp; src)
  {
      return str_to_bool(src);
  }
  </code></pre>
  
  <p>What is the correct way to support both std::string and <code>char *</code>?</p>
  
  <p>EDIT 1: the title was stupid. Fixed it.</p>
  
  <p>EDIT 2: I borrowed a solution from boost itself. Posted as a <a href="https://stackoverflow.com/questions/6559622/template-specialization-for-char-pointer/6559891#6559891">new answer</a>.</p>