wrapped0.cpp 887 B

12345678910111213141516171819202122232425262728293031
  1. // wrapped0.cpp -- using a function wrapper
  2. #include "somedefs.h"
  3. #include <iostream>
  4. #include <math.h>
  5. #include <functional>
  6. double dub(double x) {return 2.0*x;}
  7. int main()
  8. {
  9. using std::cout;
  10. using std::endl;
  11. using std::function;
  12. typedef function<double(double)> fdd;
  13. double y = 1.21;
  14. function<double(double)> ef1 = dub;
  15. function<double(double)> ef2 = std::sqrt;
  16. function<double(double)> ef3 = Fq(10.0);
  17. function<double(double)> ef4 = Fp(10.0);
  18. function<double(double)> ef5 = [](double u) {return u*u;};
  19. function<double(double)> ef6 = [](double u) {return u+u/2.0;};
  20. cout << use_f(y, function<double(double)>(dub)) << endl;
  21. cout << use_f(y, fdd(sqrt)) << endl;
  22. cout << use_f(y, ef3) << endl;
  23. cout << use_f(y, ef4) << endl;
  24. cout << use_f(y, ef5) << endl;
  25. cout << use_f(y, ef6) << endl;
  26. std::cin.get();
  27. return 0;
  28. }