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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With