dimanche 29 novembre 2015

Is it possible to bind the second parameter of a lambda function?

I'm new to C++11 lambdas and what I would like to do is something like this, where a binary lambda is turned into a unary one by binding its second parameter.

#include <functional>

int main(int argc, char *argv[])
{
   auto lambda1 = [](int a, int b) { return a+b; };
   auto lambda2 = std::bind2nd(lambda1, 5);
   return 0;
}

Compilation fails with

error: no type named 'first_argument_type' in 'struct main(int, char**)::<lambda(int, int)>'
     class binder2nd

[How] can this be done?

Aucun commentaire:

Enregistrer un commentaire