fork(1) download
  1. #include <iostream>
  2. #include <type_traits>
  3. using namespace std;
  4.  
  5. class Foo {};
  6. class Bar {};
  7.  
  8. struct Functor1
  9. {
  10. static double functor(const Foo &) { return 2.2; }
  11. };
  12.  
  13. struct Functor2
  14. {
  15. static int functor(const Bar &) { return 3; }
  16. };
  17.  
  18. template<typename Operand>
  19. auto test(const Operand &operand) -> decltype(Functor1::functor(operand))
  20. {
  21. return Functor1::functor(operand);
  22. }
  23.  
  24. template<typename Operand>
  25. auto test(const Operand &operand) -> decltype(Functor2::functor(operand))
  26. {
  27. return Functor2::functor(operand);
  28. }
  29.  
  30. int main() {
  31. cout << test(Foo()) << endl << test(Bar());
  32. return 0;
  33. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
2.2
3