title: Default parameter value in template function, depending on type
body: <p>Suppose I have this function to trim an std::string and decide to extend it, so that it removes not only spaces from the beginning and end, but also any character I pass in another string, like spaces, newlines and carriage returns.</p>
  
  <pre><code>std::string Trim ( const std::string &amp;In_Original,
    const std::string &amp;In_CharsToTrim = " \n\r" );
  </code></pre>
  
  <p>So basically, it would remove all characters present in In_CharsToTrim from the beginning and end of In_Original.</p>
  
  <p>Now, I had to write this for both std::string and std::wstring. Since I find that absurd, I chose to make use of templates, and it works, but I am unable to pass a default value, because the std::wstring version must get <code>L" \n\r"</code> as the default value (note that little L, there).</p>
  
  <p>I tried this:</p>
  
  <pre><code>template &lt;typename Type&gt; Type Trim ( const Type &amp;In_String,
    const Type &amp;In_TrimCharacters );
  </code></pre>
  
  <p>along with:</p>
  
  <pre><code>template std::string Trim ( const  std::string &amp;In_String,
    const  std::string &amp;In_TrimCharacters = " \n\r" );
  template std::wstring Trim ( const  std::wstring &amp;In_String,
    const  std::wstring &amp;In_TrimCharacters = L" \n\r" );
  </code></pre>
  
  <p>But it didn't work. It doesn't even compile.</p>
  
  <p>Currently, what I have, is a separate function for when you call without a second parameter, but this is completely the wrong approach:</p>
  
  <pre><code>template &lt;typename Type&gt; Type Trim ( const Type &amp;In_String,
    const Type &amp;In_TrimCharacters );
  std::string Trim ( const std::string &amp;In_String );
  std::wstring Trim ( const std::wstring &amp;In_String );
  </code></pre>
  
  <p>Then, in this simpler Trim function, I'm simply calling the complete version.</p>
  
  <p>So, basically, what I'm asking is this...:</p>
  
  <p>How can I pass a different default value depending on the template type? Basically, a specialization, in which the only change is the default parameter...</p>
  
  <p>In this case, to pass <code>std::string ( " \n\r" )</code> in one case, and <code>std::wstring ( L" \n\r" )</code> in the other...</p>
  
  <p>Or... is there another way to do what I'm trying to do, here?</p>