Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. void ArithmeticLambda(const int input1, const int input2, std::function<int(const int, const int)> op)
  2. {
  3.     std::cout << op(input1, input2) << '\n';
  4. }
  5.  
  6. int main()
  7. {
  8.     auto add = [](const int lhs, const int rhs) { return lhs + rhs; };
  9.     auto subtract = [](const int lhs, const int rhs) { return lhs - rhs; };
  10.     auto multiply = [](const int lhs, const int rhs) { return lhs * rhs; };
  11.     auto divide = [](const int lhs, const int rhs) { return lhs / rhs; };
  12.  
  13.     ArithmeticLambda(3, 4, add);
  14.     ArithmeticLambda(3, 4, subtract);
  15.     ArithmeticLambda(3, 4, multiply);
  16.     ArithmeticLambda(6, 3, divide);
  17.  
  18.     return EXIT_SUCCESS;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement