Boost.Bind and boost.ref propagation

Hi, Why this code asserts? struct foo { typedef void result_type; template <typename T> void operator()(T obj) const { BOOST_MPL_ASSERT ((boost::mpl::or_ < typename boost::mpl::not_ < typename boost::is_same<typename boost::unwrap_reference<T>::type, T>::type >::type , typename boost::is_reference<T>::type >)); } }; int main() { int i = 0; boost::bind(::foo(), boost::ref(i))(); } I would expect the T type to be boost::reference_wrapper<int>, but it is actually int. It is not int& as well. How do I get to propagate the boost::reference_wrapper through boost.bind to a template? I don't want to use T& for the parameter, because the algorithm accepts objects-by-value correctly, but I would like to be able to use boost.bind as I would call this algorithm with boost.ref for some data-types. foo()(boost::ref(i)); // Calls with boost::reference_wrapper<int> Thanks in advance, -- Felipe Magno de Almeida

Felipe Magno de Almeida wrote: ...
int main() { int i = 0; boost::bind(::foo(), boost::ref(i))(); }
I would expect the T type to be boost::reference_wrapper<int>, but it is actually int. It is not int& as well.
How do I get to propagate the boost::reference_wrapper through boost.bind to a template?
You can't, bind unwraps the reference_wrapper internally. Use either std::ref or your own reference wrapper.
participants (2)
-
Felipe Magno de Almeida
-
Peter Dimov