title: C++ Templates Specialization Ponderings
body: <p>I ran into a strange situation that should be solved with templates, but for some reason I fail to find the right way to do it.</p>
  
  <p>for most basic types (<strong>int, bool, char, double, long...</strong>) I use this function:</p>
  
  <pre><code>template &lt;typename T&gt;
  T foo(T val);
  </code></pre>
  
  <p>The special case is with strings, since sending an argument to the function in all cases is by sending a quoted text (like <em>"blah"</em>) which is deduced to a <strong>const char*</strong>, and the return value must be <strong>std::string</strong> like this:</p>
  
  <pre><code>template ?
  std::string foo(const char* val);
  </code></pre>
  
  <p>The code for all the basic types is the same, but the <strong>string</strong> case is special since the argument and the return value types are not the same, and the string case requires different code than the basic case.</p>
  
  <p>I've tried all kinds of strange combinations to achieve a code that compiles and works but I failed.
  I need a solution that is more elegant than writing the same code over and over again.</p>
  
  <p>Thanks!</p>