fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. template <typename UnaryFunction>
  5. class ApplyValues
  6. {
  7. typedef std::function<UnaryFunction> Performer;
  8. Performer performer;
  9. public:
  10. typedef typename Performer::argument_type argument_type;
  11.  
  12. ApplyValues( Performer p ) : performer( p ) { }
  13.  
  14. void apply( argument_type low, argument_type up ) {
  15. performer( low ); performer( up );
  16. }
  17. };
  18.  
  19. void print(double value) {
  20. std::cout << value << std::endl;
  21. }
  22.  
  23. struct print2 {
  24. void operator()(double value) {
  25. std::cout << 2 * value << std::endl;
  26. }
  27. };
  28.  
  29. int main() {
  30. using namespace std;
  31.  
  32. ApplyValues<void(double)> a(print);
  33. a.apply( 1, 99 );
  34. cout << "---" << endl;
  35. ApplyValues<void(double)> b( (print2()) );
  36. b.apply( 2, 99 );
  37. }
Success #stdin #stdout 0s 3064KB
stdin
Standard input is empty
stdout
1
99
---
4
198