fork(1) download
  1. #include <iostream>
  2. #include <functional>
  3. #include <map>
  4. using namespace std;
  5.  
  6. enum E { A, B };
  7.  
  8. struct Some {
  9. map<E,function<void()>> m;
  10.  
  11. Some ();
  12. void process(E);
  13. template <int N> void func();
  14. };
  15.  
  16. template<> void Some::func<E::A>() {
  17. cout << "A\n";
  18. }
  19.  
  20. template<> void Some::func<E::B>() {
  21. cout << "B\n";
  22. }
  23.  
  24. Some::Some ()
  25. : m (
  26. {
  27. {E::A, bind(&Some::func<E::A>, this)}
  28. ,{E::B, bind(&Some::func<E::B>, this)}
  29. }
  30. )
  31. {
  32. }
  33.  
  34. void Some::process(E x) {
  35. m[x]();
  36. }
  37.  
  38. int main() {
  39. Some foo;
  40. foo.process(E::A);
  41. foo.process(E::B);
  42. }
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
A
B