fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template<typename T>
  6. struct is_pure_func_ptr: public std::false_type {};
  7. template<typename Ret, typename... Args>
  8. struct is_pure_func_ptr<Ret(Args...)>: public std::true_type {};//detecting functions themselves
  9. template<typename Ret, typename... Args>
  10. struct is_pure_func_ptr<Ret(*)(Args...)>: public std::true_type {};//detecting function pointers
  11. void f1()
  12. {};
  13.  
  14. int f2(int)
  15. {};
  16.  
  17. int f3(int, int)
  18. {};
  19.  
  20. struct Functor
  21. {
  22. void operator ()()
  23. {}
  24. };
  25.  
  26. int main()
  27. {
  28. cout << is_pure_func_ptr<decltype(f1)>::value << endl; // output true
  29. cout << is_pure_func_ptr<decltype(f2)>::value << endl; // output true
  30. cout << is_pure_func_ptr<decltype(f3)>::value << endl; // output true
  31. cout << is_pure_func_ptr<decltype(&f3)>::value << endl; // output true
  32. cout << is_pure_func_ptr<Functor>::value << endl; // output false
  33. cout << is_pure_func_ptr<char*>::value << endl; // output false
  34. }
Success #stdin #stdout 0s 2928KB
stdin
Standard input is empty
stdout
1
1
1
1
0
0