fork download
  1. #include <iostream>
  2. #include <utility>
  3. #include <memory>
  4. #include <cstdint>
  5.  
  6. template <typename V, typename T>
  7. std::int8_t test(V&& v, T&& t, decltype((t.*v)((int)0))* = 0) {
  8. return 0;
  9. }
  10.  
  11. template <typename V, typename T>
  12. std::int16_t test(V&& v, T&& t, decltype((t->*v)((int)0))* = 0) {
  13. return 0;
  14. }
  15.  
  16. template <typename V, typename T>
  17. std::int32_t test(V&& v, T&& t, decltype((t.operator->()->*v)((int)0))* = 0) {
  18. return 0;
  19. }
  20.  
  21. std::int64_t test(...) {
  22. return 0;
  23. }
  24.  
  25. struct ichikawa {
  26. int fun(int a) const {
  27. return 2 * a;
  28. }
  29. };
  30.  
  31. int main() {
  32. ichikawa ic;
  33. std::unique_ptr<ichikawa> sp(new ichikawa);
  34. int (ichikawa::*pF)(int)const = &ichikawa::fun;
  35.  
  36. std::cout << (*sp.*pF)(7) << std::endl; //14
  37.  
  38. auto result1 = test(pF, ic);
  39. auto result2 = test(pF, &ic);
  40. auto result3 = test(pF, sp);
  41. auto result4 = test(2014, 01/02);
  42.  
  43. std::cout << sizeof(result1) << std::endl;
  44. std::cout << sizeof(result2) << std::endl;
  45. std::cout << sizeof(result3) << std::endl;
  46. std::cout << sizeof(result4) << std::endl;
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
14
1
2
4
8