I came across a bug with std::bind in Visual C++ 2010 SP1. The problem occurs in the following code:
#include <iostream>
#include <functional>
using namespace std;
struct Foo
{
typedef void result_type;
template<typename T>
void operator()(T &n)
{
n = 5;
}
};
int main()
{
int n = 0;
Foo f;
auto func = bind(f, ref(n));
func();
cout << n << endl;
return 0;
}
This should result in the template argument for Foo::operator() getting resolved as "int", but instead it gets resolved as "std::reference_wrapper<int>" which then fails to compile because there is no suitable operator= to do the assignment.
The code does compile and run successfully on g++ 4.6.1, and using boost::bind/boost::ref instead of the std library versions also does the right thing. You can see the code working correctly here.
I submitted a bug report, please vote on it if you can reproduce it.
Add your 2¢