Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://en.cppreference.com/w/cpp/types/enable_if" rel="noreferrer"><code>std::enable_if</code></a> works through the principle of <a href="http://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error" rel="noreferrer">substitution failure is not an error</a> (SFINAE), which states that when certain types of error occur in instantiating a function template, the program continues to compile with that function template not participating in overload resolution.</p> <p>For SFINAE to kick in, (a) it has to be used on a function (or method) template and (b) it has to be dependent on a template parameter. Your program fails on both counts.</p> <p>To make the <code>enable_if</code> dependent on a template parameter, the easiest thing is to add a default parameter:</p> <pre><code>template&lt;typename T = void&gt; typename enable_if&lt;is_64_bit::value, T&gt;::type my_memcpy(void* target, const void* source, size_t n) </code></pre> <p>However, this is not in general a sensible use of <code>enable_if</code>; since it depends on intercepting compile errors it tends to be expensive. In your case a template specialization would be a much better idea:</p> <pre><code>#include &lt;iostream&gt; template&lt;int = sizeof(void *)&gt; void my_memcpy(void* target, const void* source, size_t n); template&lt;&gt; void my_memcpy&lt;8&gt;(void* target, const void* source, size_t n) { std::cout &lt;&lt; "64 bit memcpy" &lt;&lt; std::endl; } template&lt;&gt; void my_memcpy&lt;4&gt;(void* target, const void* source, size_t n) { std::cout &lt;&lt; "32 bit memcpy" &lt;&lt; std::endl; } </code></pre>
    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. 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.
    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