Note that there are some explanatory texts on larger screens.

plurals
  1. POChecking a member exists, possibly in a base class, VS2005/08 version
    text
    copied!<p>In <a href="https://stackoverflow.com/questions/9530928/checking-a-member-exists-possibly-in-a-base-class-c11-version">Checking a member exists, possibly in a base class, C++11 version</a>, we developed a C++11 version of the classical member-checking type-trait from <a href="https://stackoverflow.com/questions/1966362/sfinae-to-check-for-inherited-member-functions">SFINAE to check for inherited member functions</a> that also works with C++11 <code>final</code> classes, but uses C++11 features (namely, <code>decltype</code>), too:</p> <pre><code>template&lt;typename T&gt; class has_resize_method { struct Yes { char unused[1]; }; struct No { char unused[2]; }; static_assert(sizeof(Yes) != sizeof(No)); template&lt;class C&gt; static decltype(std::declval&lt;C&gt;().resize(10), Yes()) test(int); template&lt;class C&gt; static No test(...); public: static const bool value = (sizeof(test&lt;T&gt;(0)) == sizeof(Yes)); }; </code></pre> <p>MSVC has had <code>final</code> as a non-standard extension named <a href="http://msdn.microsoft.com/en-us/library/0w2w91tf%28v=vs.80%29.aspx" rel="nofollow noreferrer"><code>sealed</code></a> since VS2005, but <code>decltype</code> has only been added in VS2010. That leaves VS2005 and 2008 where a class that is marked as <code>sealed</code> still breaks the classical type-trait and the C++11 version cannot be used.</p> <p>So, is there a way to formulate <code>has_resize_method</code> such that it works on VC2005/08 <code>sealed</code> classes, too?</p> <p>Obviously, just as using C++11-only features to work around a C++11-only problem (<code>final</code>) is fine, so would be using VS-only extensions to work around the VS2005/08-only problem of <code>sealed</code> classes, but if there's a solution that works for all three sets of compilers {C++11,{VS2005,VS2008},all others}, that would be cool, but probably too much to ask for :)</p>
 

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