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
Recursive Function Calling Example with Stack Addresses
Ordered Graphs
Unqualified free functions
C++ Operator Overloading
Linear search
projecte1
overloadresolution
Integer conversions
Task on Задача C. Белочка
non-template template parameters for container stream insertion: SFINAE