In Checking a member exists, possibly in a base class, C++11 version, we developed a C++11 version of the classical member-checking type-trait from SFINAE to check for inherited member functions that also works with C++11 final
classes, but uses C++11 features (namely, decltype
), too:
template<typename T>
class has_resize_method {
struct Yes { char unused[1]; };
struct No { char unused[2]; };
static_assert(sizeof(Yes) != sizeof(No));
template<class C>
static decltype(std::declval<C>().resize(10), Yes()) test(int);
template<class C>
static No test(...);
public:
static const bool value = (sizeof(test<T>(0)) == sizeof(Yes));
};
MSVC has had final
as a non-standard extension named sealed
since VS2005, but decltype
has only been added in VS2010. That leaves VS2005 and 2008 where a class that is marked as sealed
still breaks the classical type-trait and the C++11 version cannot be used.
So, is there a way to formulate has_resize_method
such that it works on VC2005/08 sealed
classes, too?
Obviously, just as using C++11-only features to work around a C++11-only problem (final
) is fine, so would be using VS-only extensions to work around the VS2005/08-only problem of sealed
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 :)