Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Depending on what you mean by <em>exclude the types <code>string</code> or <code>char</code></em>. If you want it not to link you can declare but not define specializations for the types:</p> <pre><code>template &lt;&gt; void parse&lt;std::string&gt;( std::string &amp; value, const std::string&amp; token ); </code></pre> <p>The compiler will see the specialization and not generate the code. The linker will fail as the symbol is not defined in any translation unit. </p> <p>The second approach, a bit more complicated is not to fail at link time, but to make the compiler not accept the template for those types. This can be done with SFINAE, which is simpler in C++11, but if you need a C++03 solution you can google for it or add a comment:</p> <pre><code>template &lt;typename T, typename = typename std::enable_if&lt;!std::is_same&lt;T,std::string&gt; &amp;&amp; !std::is_same&lt;T,char&gt;&gt;::type &gt; void parse( T &amp; t, const std::string&amp; token ) { // ... } </code></pre> <p>(I have not run this through a compiler so the syntax might be a bit off, play with it) The compiler will see the template, and when it tries to perform the substitution of the type <code>T</code> it will fail due to the <code>std::enable_if&lt;...&gt;::type</code> not resolving to a type.</p> <p>In general, what you probably want is to provide different overloads that perform a specific version of the <code>parse</code> and take precedence:</p> <pre><code>void parse( std::string&amp; v, const std::string&amp; token ) { v = token; } </code></pre> <p>Note that this is not a template, but a regular function. A non-templated function will be a better match than a templated one when the arguments of the call are perfect matches.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload