Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::bind - compiling unexpected (undeclared identifier) error in visual studio

Well another troubling error message for me, if I understand std::bind correctly I can arguments like _1 to to the define a non-given argument? Right? Well considering the following line:

std::function<bool(value_type, const std::string &)> 
                             func(std::bind(&Pred, _1, "name"));

This should work, right? This would be used for a std::find_if() function, as such the first argument should be the value type & the second the string.

However visual studio 2010 complains about this with the following error message:

error C2065: '_1' : undeclared identifier

That's just weird, how can I say in visual studio "hey the first argument isn't bound". Pred is a simple funciton taking value_type, const std::string& as arguments - returning a boolean.

like image 711
paul23 Avatar asked Dec 16 '22 13:12

paul23


1 Answers

In your case, you want this:

std::function<bool(value_type, const std::string &)> 
                         func(std::bind(&Pred, std::placeholders::_1, "name"));
like image 58
Tony The Lion Avatar answered Dec 28 '22 23:12

Tony The Lion