Run Code
|
API
|
Code Wall
|
Users
|
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
Please
log in
to post a comment.
pack expansion
Throttle Example (Send two requests every two seconds)
DESim Example with Hash Table Starter Code
Uno v2
AnnotateAttr templated test
illegal instruction (SIGILL)
Linear search
back_inserter example
Optional conversions
GreedyProblem1
Please log in to post a comment.