Error in the placeholder in a binder

时间:2016-04-04 18:49:40

标签: c++

void f(int i,const string& s){cout << i << s;}

auto g = bind(f,2,_1);

I get an error, _1 was not declared in this scope

1 个答案:

答案 0 :(得分:2)

好:

using namespace std::placeholders;
auto g = std::bind(f, 2, _1);

更好:

auto h = std::bind(f, 2, std::placeholders::_1);

最佳:

auto i = [](auto&& x) { f(2, x); };

额外奖励积分:

auto j = [](auto&& x) {
    using type = std::decay_t<decltype(x)>;
    f(2, std::forward<type>(x));
};