cpp bind all arguments code example
Example: of c++ bind class member function
#include <iostream>
#include <functional>
double my_divide (double x, double y) {return x/y;}
struct MyPair {
double a,b;
double multiply() {return a*b;}
};
int main () {
using namespace std::placeholders;
auto fn_five = std::bind (my_divide,10,2);
std::cout << fn_five() << '\n';
auto fn_half = std::bind (my_divide,_1,2);
std::cout << fn_half(10) << '\n';
auto fn_invert = std::bind (my_divide,_2,_1);
std::cout << fn_invert(10,2) << '\n';
auto fn_rounding = std::bind<int> (my_divide,_1,_2);
std::cout << fn_rounding(10,3) << '\n';
MyPair ten_two {10,2};
auto bound_member_fn = std::bind (&MyPair::multiply,_1);
std::cout << bound_member_fn(ten_two) << '\n';
auto bound_member_data = std::bind (&MyPair::a,ten_two);
std::cout << bound_member_data() << '\n';
return 0;
}