#include <iostream>
#include <functional>

int print(int a){
  std::cout << a << std::endl;
  return 0;
}

int print_sum(int a, int b, int c){
  std::cout << a+b+c << std::endl;
  return 0;
}

class classA {
public:
  int m_a;
  std::function<int(int, int)> m_func[2] = {
    [this](int a, int b){
      if (m_a % 2 == 0) {
        return a;
      }else{
        return b;
      }
    },
    [this](int a, int b){
      if (m_a % 2 == 0) {
        return a;
      }else{
        return b;
      }
    }
  };
  classA(){
    m_a = 0;
  }
  void step(){
    std::cout << m_func[0](m_a, m_a*2) << std::endl;
    m_a ++;
  }
  void testPrint(int a){
    std::cout << a << std::endl;
  }
};

int main(){
  std::function<int(int)> func1(print);
  func1(11);

  std::function<int(int)> func2([](int a) { std::cout << a << std::endl; return 0; }); // 2
  func2(22);

  std::function<int(int)> func3 = std::bind(print, std::placeholders::_1);
  func3(33);

  classA cla;
  std::function<void(int)> func4 = std::bind(&classA::testPrint, &cla, std::placeholders::_1);
  func4(44);
  cla.step();
  cla.step();
  cla.step();
  cla.step();

  std::function<int(int, int)> func5 = std::bind(print_sum, 1, std::placeholders::_1, std::placeholders::_2);
  func5(55, 1);

  return 0;
}
