I have a map of actions to be taken upon certain choice,
struct option {
int num;
std::string txt;
std::function<void(void)> action;
};
void funct_with_params(int &a, int &b)
{
a = 3; b = 4;
}
int param1 = 1;
int param2 = 3;
I want to initialize vector of those in the new initializer list fashion:
const std::vector<option> choices
{
{
1,
"sometext",
std::bind(&funct_with_params, std::ref(param1), std::ref(param2))
},
}
I can't get the initialization in the vector for function to work, is there a method of passing the std::bind
to the vector in some way?
I was able to make the example work by using lambda expression instead of the bind, is there something I am missing? Or is it not the proper way of using std::bind
?
I am using C++11 since I'm unable to move to a newer standard.