std::bind not working
I can't get std::bind
to work the same way 开发者_运维技巧boost::bind
works. Either I'm not using it correctly, or my compiler (GCC 4.4.5) doesn't implement it correctly yet.
I have two functions:
void f(int x, int y)
{
cout << x << " | " << y << endl;
}
template <class UnaryFunction>
void g(UnaryFunction func)
{
func(100);
}
I use bind to call f
as a unary function in g:
g(std::bind(f, 10, std::placeholders::_1));
This results in a compiler error:
error: no match for call to ‘(std::_Bind<void (*(int, std::_Placeholder<1>))(int, int)>) (int)’
... followed by a page or so of template compiler vomit.
If I use boost::bind
, like:
g(boost::bind(f, 10, _1));
...it works fine. Are the semantics of std::bind
somehow different, or is this a compiler issue?
It looks like it's just your version of compiler, gcc 4.5.1 (via ideone.com) and 4.6.0 compile it correctly.
精彩评论