Note that there are some explanatory texts on larger screens.

plurals
  1. POChecking a member exists, possibly in a base class, C++11 version
    primarykey
    data
    text
    <p>In <a href="https://stackoverflow.com/a/1967183/134841">https://stackoverflow.com/a/1967183/134841</a>, a solution is provided for statically checking whether a member exists, possibly in a subclass of a type:</p> <pre><code>template &lt;typename Type&gt; class has_resize_method { class yes { char m;}; class no { yes m[2];}; struct BaseMixin { void resize(int){} }; struct Base : public Type, public BaseMixin {}; template &lt;typename T, T t&gt; class Helper{}; template &lt;typename U&gt; static no deduce(U*, Helper&lt;void (BaseMixin::*)(), &amp;U::foo&gt;* = 0); static yes deduce(...); public: static const bool result = sizeof(yes) == sizeof(deduce((Base*)(0))); }; </code></pre> <p>However, it doesn't work on C++11 <code>final</code> classes, because it inherits from the class under test, which <code>final</code> prevents.</p> <p>OTOH, this one:</p> <pre><code>template &lt;typename C&gt; struct has_reserve_method { private: struct No {}; struct Yes { No no[2]; }; template &lt;typename T, typename I, void(T::*)(I) &gt; struct sfinae {}; template &lt;typename T&gt; static No check( ... ); template &lt;typename T&gt; static Yes check( sfinae&lt;T,int, &amp;T::reserve&gt; * ); template &lt;typename T&gt; static Yes check( sfinae&lt;T,size_t,&amp;T::reserve&gt; * ); public: static const bool value = sizeof( check&lt;C&gt;(0) ) == sizeof( Yes ) ; }; </code></pre> <p>fails to find the <code>reserve(int/size_t)</code> method in baseclasses.</p> <p>Is there an implementation of this metafunction that both finds <code>reserved()</code> in baseclasses of <code>T</code> and still works if <code>T</code> is <code>final</code>?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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