Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this instead:</p> <pre><code>#include &lt;string&gt; #include &lt;vector&gt; #include &lt;iostream&gt; template&lt;typename U&gt; struct CheckSignature { enum {SizeTrue = 1, SizeFalse = 2}; typedef char ReturnTrue[SizeTrue]; typedef char ReturnFalse[SizeFalse]; typedef typename U::iterator (U::*InsertSig)(typename U::iterator, typename U::value_type const &amp;); template &lt;InsertSig f&gt; struct dummy_type { }; template &lt;typename T&gt; static ReturnTrue &amp;CheckInsert(T*, dummy_type&lt;&amp;T::insert&gt; dummy = dummy_type&lt;&amp;T::insert&gt;()); static ReturnFalse &amp;CheckInsert(...); static const bool value = (sizeof(CheckInsert(((U*)0))) == sizeof(ReturnTrue)); }; int main() { if(CheckSignature&lt;std::string &gt;::value) { std::cout &lt;&lt; "String class has proper insert function" &lt;&lt; std::endl; }; //OK, does not print, as expected. if(CheckSignature&lt;std::vector&lt;int&gt; &gt;::value) { std::cout &lt;&lt; "Vector class has proper insert function" &lt;&lt; std::endl; }; //OK, does print, as expected. return 0; } </code></pre> <p>The reason why it doesn't work is because, in your version, taking the address of the insert function will fail at the call site, not at the substitution (which is not an error). The above will make sure that if the type U (templated to T) cannot be used to obtain a member function pointer to insert which is convertable to the given signature, it will fail to substitute for the dummy parameter, and thus, revert to the ellipsis version.</p>
    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