On reference_wrapper and callable objects
- by Nicola Bonelli
Given the following callable object:
struct callable : public std::unary_function <void, void>
{
void
operator()() const
{
std::cout << "hello world" << std::endl;
}
};
a std::tr1::reference_wrapper< calls through it:
callable obj;
std::tr1::ref(obj)();
Instead, when the operator() accepts an argument:
struct callable : public std::unary_function <int, void>
{
void
operator()(int n) const
{
std::cout << n << std::endl;
}
};
std::tr1::bind accepts a reference_wrapper to it as a callable wrapper...
callable obj;
std::tr1::bind( std::tr1::ref(obj), 42 )();
but what's wrong with this?
std::tr1::ref(obj)(42);