Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Member function detection
#include <iostream> using namespace std; struct A { void f() { cout << "A::f()\n"; } }; class B { }; void f() { cout << "::f()\n"; } // Compile-time function selection. template <class T, int S> struct Call { Call(T& t) {::f();} }; template <class T> struct Call<T, 1> { Call(T& t) { t.f(); } }; // Compile-time member detection. class C1 { char c[1]; }; class C2 { char c[2]; }; template<class T> C1 Detect(decltype(&T::f)); template<class T> C2 Detect(...); template <class T> void callF( T& t ) { Call<T, sizeof(Detect<T>(0))> call(t); } int main() { static_assert(sizeof(C1) == 1, ""); static_assert(sizeof(C2) == 2, ""); A a; B b; callF(a); callF(b); return 0; }
run
|
edit
|
history
|
help
0
Yo que se
BadCastAllExcept
ExceptionHandling3
Test 8(2020)
alternate list
prepend
Web Browser History - DLL
string-Orderly words
Base conversion
merge without extra space Gap method ALgorithm