Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <functional>
  3. using namespace std;
  4. using namespace std::placeholders;
  5.  
  6. bool check1(int a, int b) { return a + b > 0; }
  7. bool check2(int a, double b) { return a + b > 0; }
  8. bool check3(int a) { return a > 0; }
  9.  
  10. struct AlwaysTrue {
  11.     bool operator()(int i) const {
  12.         return true;
  13.     }
  14. };
  15.  
  16. template <class FClass = AlwaysTrue>
  17. bool Foo(FClass foo = FClass()) {
  18.     for (int i = 0; i < 3; ++i) {
  19.         cout << foo(i) << " ";
  20.     }
  21.     cout << endl;
  22. }
  23.  
  24. int main() {
  25.     Foo(std::bind(check1, _1, 0));
  26.     Foo(std::bind(check2, _1, .0));
  27.     Foo(std::bind(check3, _1));
  28.     Foo();
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement