fork(1) download
  1. #include <cmath>
  2. #include <functional>
  3. #include <iomanip>
  4. #include <iostream>
  5. #include <type_traits>
  6. using namespace std;
  7.  
  8. template <typename T, typename F>
  9. auto func(T && t, F && f)
  10. -> typename enable_if<is_same<bool, typename result_of<F(T)>::type>::value, bool>::type
  11. {
  12. return f(t);
  13. }
  14.  
  15. bool is_pi(double d)
  16. {
  17. // approximately
  18. return d == 3.1415926;
  19. }
  20.  
  21. int main()
  22. {
  23. cout << boolalpha << func(42, [](int answer){ return answer == 42; }) << endl;
  24. cout << boolalpha << func(M_PI, is_pi);
  25. return 0;
  26. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
true
false