Имеется следующий вызываемый объект:
struct callable : public std::unary_function <void, void>
{
void
operator()() const
{
std::cout << "hello world" << std::endl;
}
};
a std::tr1::reference_wrapper<>
звонки через него:
callable obj;
std::tr1::ref(obj)();
Вместо этого, когда operator()
принимает аргумент:
struct callable : public std::unary_function <int, void>
{
void
operator()(int n) const
{
std::cout << n << std::endl;
}
};
std::tr1::bind
принимает reference_wrapper в качестве вызываемой оболочки ...
callable obj;
std::tr1::bind( std::tr1::ref(obj), 42 )();
а что с этим не так?
std::tr1::ref(obj)(42);
g ++ - 4.4 не компилируется со следующей ошибкой:
test.cpp:17: error: no match for call to ‘(std::tr1::reference_wrapper<const callable>) (int)’
/usr/include/c++/4.4/tr1_impl/functional:462: note: candidates are: typename std::tr1::result_of<typename std::tr1::_Function_to_function_pointer<_Tp, std::tr1::is_function::value>::type(_Args ...)>::type std::tr1::reference_wrapper<_Tp>::operator()(_Args& ...) const [with _Args = int, _Tp = const callable]