Created
October 1, 2016 09:52
-
-
Save Garciat/677e95fc3fe813e1646e23fff00940d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <utility> | |
template<typename T, T... PMFs> | |
struct method_choice; | |
template<typename C, typename R, R C::* PMF, R C::*... PMFs> | |
struct method_choice<R C::*, PMF, PMFs...> { | |
template<typename... A> | |
method_choice(int choice, C &subject, A... args) { | |
if (choice == 0) { | |
(subject.*PMF)(std::forward<A>(args)...); | |
} else { | |
method_choice<R C::*, PMFs...>(choice - 1, subject, std::forward<A>(args)...); | |
} | |
} | |
}; | |
template<typename C, typename R> | |
struct method_choice<R C::*> { | |
template<typename... A> | |
method_choice(int, C &, A...) { | |
// die? | |
} | |
}; | |
extern volatile int poop; | |
struct what { | |
void f(int x) { poop += x; } | |
void g(int x) { poop *= x; } | |
void h(int x) { poop -= x; } | |
}; | |
void hello(int k) { | |
what w; | |
method_choice<void (what::*)(int), &what::f, &what::g, &what::h>(k, w, 42); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment