#include #include "bind.hpp" int calc (int a, int b) { return a+b; } float calc_f (float a, float b) { return a+b; } int main () { const auto & f = boost::bind (calc, 40, 2); // leave a _1 just to check it works with incomplete binding const auto & ff = boost::bind (calc_f, 1.5, _1); // ref std::cout << f() << std::endl; std::cout << ff(2.3) << std::endl; // + std::cout << "ADD" << std::endl; const auto & f_plus_3 = f + 3; const auto & _3_plus_f = 3 + f; // NB : "3.14" alone don't work (compile error) // need exact type match : float() or ...f const auto & ff_plus_PI = ff + float(3.14); const auto & PI_plus_ff = 3.14f + ff; std::cout << f_plus_3() << std::endl; std::cout << _3_plus_f() << std::endl; std::cout << ff_plus_PI(2.3) << std::endl; std::cout << PI_plus_ff(2.3) << std::endl; // - std::cout << "SUB" << std::endl; const auto & f_minus_3 = f - 3; const auto & _3_minus_f = 3 - f; const auto & ff_minus_PI = ff - float(3.14); const auto & PI_minus_ff = 3.14f - ff; std::cout << f_minus_3() << std::endl; std::cout << _3_minus_f() << std::endl; std::cout << ff_minus_PI(2.3) << std::endl; std::cout << PI_minus_ff(2.3) << std::endl; // * std::cout << "MUL" << std::endl; const auto & f_by_5 = f * 5; const auto & _5_by_f = 5 * f; const auto & ff_by_PI = ff * float(3.14); const auto & PI_by_ff = 3.14f * ff; std::cout << f_by_5() << std::endl; std::cout << _5_by_f() << std::endl; std::cout << ff_by_PI(2.3) << std::endl; std::cout << PI_by_ff(2.3) << std::endl; // / std::cout << "DIV" << std::endl; const auto & f_div_5 = f / 5; const auto & _5_div_f = 5 / f; const auto & ff_div_PI = ff / float(3.14); const auto & PI_div_ff = 3.14f / ff; std::cout << f_div_5() << std::endl; std::cout << _5_div_f() << std::endl; std::cout << ff_div_PI(2.3) << std::endl; std::cout << PI_div_ff(2.3) << std::endl; // composition test std::cout << "COMBO" << std::endl; const auto & composed= 3.14f*((ff/2.f + 3.f) - 4.f); std::cout << composed(2.3) << std::endl; return 0; }