Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
How to test call member?
//clang 3.7.0 #include <iostream> #include <type_traits> class SCallFailure{}; template<typename T> struct Has_Call { static SCallFailure test(...); template<typename... Args> static auto test(Args... args ) -> decltype( std::declval<T>().call(args...) ); }; template<typename T> struct HasCallS : std::true_type {}; template<> struct HasCallS<SCallFailure> : public std::false_type {}; template<typename T, typename... Args> constexpr bool hasCall(Args... args) { typedef decltype(Has_Call<T>::test(args...)) R; return HasCallS<R>::value; } class A { public: int call(int,int){ return 0; } }; class B { public: int call(){ return 0; } }; class C {}; int main() { std::cout << "A " << (hasCall<A>(0,0) ? "has " : "not have ") << " int call(int,int) member function" << std::endl; std::cout << "B " << (hasCall<B>() ? "has " : "not have ") << " int call() member function" << std::endl; //std::cout << "C " << (hasCall<C>() ? "has " : "not have ") << " int call() member function" << std::endl; return 0; }
run
|
edit
|
history
|
help
0
Virtual Function Example
Range List for C++
Union-Struct-uint32_t byte order
Access to temporary object
Variadic Template: Make Index Sequence
Fundamentos de programación. Tema 7. Ejercicio 6.
why
Pascals Triangle
test
std::99 bottles of beer!