Using SFINAE to detect a member function [duplicate]
问题 This question already has answers here : Is it possible to write a template to check for a function's existence? (25 answers) Closed 6 years ago . In C++11, to find out whether a class has a member function size , you could define the following test helper: template <typename T> struct has_size_fn { typedef char (& yes)[1]; typedef char (& no)[2]; template <typename C> static yes check(decltype(&C::size)); template <typename> static no check(...); static bool const value = sizeof(check<T>(0))