相关疑难解决方法(0)

为什么在C++ 14中使用std :: bind over lambdas?

在C++ 11之前我使用过boost::bind或者boost::lambda很多.该bind部分使其成为标准库(std::bind),另一部分成为核心语言(C++ lambdas)的一部分,并使lambdas的使用变得更加容易.如今,我几乎没用std::bind,因为我几乎可以用C++ lambdas做任何事情.std::bind我可以想到一个有效的用例:

struct foo
{
  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"
Run Code Online (Sandbox Code Playgroud)

相当于C++ 14的等价物

auto f = []( auto a, auto b ){ cout << a << ' ' << b; }
f( "test", 1.2f …
Run Code Online (Sandbox Code Playgroud)

c++ lambda bind c++14

56
推荐指数
3
解决办法
3万
查看次数

标签 统计

bind ×1

c++ ×1

c++14 ×1

lambda ×1