Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The template <code>template&lt; bool B, class T = void &gt; struct enable_if</code> is specialized so that it only has a <code>typedef type</code> when the condition B is <code>true</code>.</p> <p>Your compiler is correct. There is no typedef for <code>type</code> in <code>struct std::enable_if&lt;false, void&gt;</code>. There is only a typedef in <code>struct std::enable_if&lt;true, void&gt;</code>.</p> <p>For more info look <a href="http://en.cppreference.com/w/cpp/types/enable_if" rel="nofollow noreferrer">here</a>.</p> <p>So to fix your problem you need to make sure that the <code>enable_if</code> which has a B that evaluates to <code>false</code> never gets compiled. You can achieve this with the help of <a href="http://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error" rel="nofollow noreferrer">SFINAE</a> by making <code>my_memcpy</code> a function template. The compiler will then not report an error when failing to compile the function template where B evaluates to <code>false</code> and will successfully compile and use the function where B evaluates to <code>true</code>. </p> <pre><code>#include &lt;iostream&gt; #include &lt;type_traits&gt; using namespace std; struct is_64_bit { static const bool value = sizeof(void*) == 8; }; template&lt;typename T&gt; typename enable_if&lt;is_64_bit::value, T&gt;::type my_memcpy(T* target, const T* source, size_t n) { cout &lt;&lt; "64 bit memcpy" &lt;&lt; endl; } template&lt;typename T&gt; typename enable_if&lt;!is_64_bit::value, T&gt;::type my_memcpy(T* target, const T* source, size_t n) { cout &lt;&lt; "32 bit memcpy" &lt;&lt; endl; } </code></pre>
    singulars
    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