Checking a member exists, possibly in a base class, C++11 version

Actually, things got much easier in C++11 thanks to the decltype and late return bindings machinery. Now, it’s just simpler to use methods to test this: // Culled by SFINAE if reserve does not exist or is not accessible template <typename T> constexpr auto has_reserve_method(T& t) -> decltype(t.reserve(0), bool()) { return true; } // Used … Read more

check variadic templates parameters for uniqueness

Passing a pointer to base_all<U…> merely requires the existence of a declaration of base_all<U…>. Without attempting the to access the definition, the compiler won’t detect that the type is actually ill-defined. One approach to mitigate that problem would be to use an argument which requires a definition of base_all<U…>, e.g.: template< class …T> struct base_all … Read more

Find out whether a C++ object is callable

I think this trait does what you want. It detects operator() with any kind of signature even if it’s overloaded and also if it’s templatized: template<typename T> struct is_callable { private: typedef char(&yes)[1]; typedef char(&no)[2]; struct Fallback { void operator()(); }; struct Derived : T, Fallback { }; template<typename U, U> struct Check; template<typename> static … Read more