Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::bind not working

Tags:

c++

c++11

bind

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?

like image 998
Channel72 Avatar asked Apr 16 '11 23:04

Channel72


1 Answers

It looks like it's just your version of compiler, gcc 4.5.1 (via ideone.com) and 4.6.0 compile it correctly.

like image 146
Vitus Avatar answered Oct 16 '22 06:10

Vitus