fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. class Toto
  5. {
  6. public:
  7. int test(float f) { std::cout << "Toto::test " << f << std::endl; return 0; }
  8. } toto;
  9.  
  10. int test(float f)
  11. {
  12. std::cout << "test " << f << std::endl;
  13. return 0;
  14. }
  15.  
  16. namespace details
  17. {
  18. template <typename T, T t>
  19. struct func_impl
  20. {
  21. void operator () () const { t(4.0f); }
  22. };
  23.  
  24. template <typename T, int (T::*method)(float)>
  25. struct func_impl<int (T::*)(float), method>
  26. {
  27. void operator () () const { (toto.*method)(5.0f); }
  28. };
  29.  
  30.  
  31. }
  32.  
  33.  
  34. template <typename T, T t>
  35. void func()
  36. {
  37. details::func_impl<T, t>{}();
  38. }
  39.  
  40. int main(int, char**)
  41. {
  42. func<int(*)(float), &test>();
  43. func<int (Toto::*)(float), &Toto::test>();
  44. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
test 4
Toto::test 5