fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. void foo(int a, int b, int c) {
  5. std::cout << "a: " << a << "\n" "b: " << b << "\n" "c: " << c << "\n";
  6. }
  7.  
  8. int main() {
  9. auto foo_normal = std::bind(foo, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
  10. auto foo_reversed = std::bind(foo, std::placeholders::_3, std::placeholders::_2, std::placeholders::_1);
  11. auto foo_with_a1 = std::bind(foo, 1, std::placeholders::_1, std::placeholders::_2);
  12. auto foo_with_b2 = std::bind(foo, std::placeholders::_1, 2, std::placeholders::_2);
  13. auto foo_with_c3 = std::bind(foo, std::placeholders::_1, std::placeholders::_2, 3);
  14. auto foo_with_a1c3 = std::bind(foo, 1, std::placeholders::_1, 3);
  15. auto foo_with_a1b2c3 = std::bind(foo, 1, 2, 3);
  16.  
  17. foo_normal(1, 2, 3);
  18. foo_reversed(3, 2, 1);
  19. foo_with_a1(2, 3);
  20. foo_with_b2(1, 3);
  21. foo_with_c3(1, 2);
  22. foo_with_a1c3(2);
  23. foo_with_a1b2c3();
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 4408KB
stdin
Standard input is empty
stdout
a: 1
b: 2
c: 3
a: 1
b: 2
c: 3
a: 1
b: 2
c: 3
a: 1
b: 2
c: 3
a: 1
b: 2
c: 3
a: 1
b: 2
c: 3
a: 1
b: 2
c: 3