4

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.

paul23
  • 8,799
  • 12
  • 66
  • 149

1 Answers1

12

In your case, you want this:

std::function<bool(value_type, const std::string &)> 
                         func(std::bind(&Pred, std::placeholders::_1, "name"));
Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
  • hmm that actually made sense... en.cppreference.com/w/cpp/utility/functional/bind Put me on the wrong foot here :P – paul23 Mar 12 '13 at 11:25
  • 1
    @paul23 yes, the page was not very clear about the placeholders being in a different namespace - I just edited the page to make that more obvious :-) – Arne Mertz Mar 12 '13 at 11:28