Warum std :: bind über Lambdas in C ++ 14?

Vor C++11, die ich verwendet boost::bind oder boost::lambda viel. Die bind Teil und schaffte es in der standard-Bibliothek (std::bind) der andere Teil wurde Teil der core-Sprache (C++ Lambda-Ausdrücke) und die Nutzung von lambdas viel einfacher. Heute habe ich kaum Verwendung std::bindda kann ich fast alles mit C++ Lambda-Ausdrücke. Es gibt eine gültige use-case für std::bind die ich mir denken kann:

struct foo
{
  typedef void result_type;

  template < typename A, typename B >
  void operator()(A a, B b)
  {
    cout << a << ' ' << b;
  }
};

auto f = bind(foo(), _1, _2);
f( "test", 1.2f ); //will print "test 1.2"

Den C++14-äquivalent für das wäre

auto f = []( auto a, auto b ){ cout << a << ' ' << b; }
f( "test", 1.2f ); //will print "test 1.2"

Viel kürzer und übersichtlicher. (In C++11 das doch nicht funktionieren, weil der auto-Parameter.) Gibt es eine andere zulässige Verwendung für std::bind schlagen der C++ - lambdas alternative oder ist std::bind überflüssig mit C++14?

InformationsquelleAutor der Frage Ralph Tandetzky | 2013-06-28

Schreibe einen Kommentar