Andrey Semashev wrote:
template< typename T > void foo1(T const& t) { foo(boost::ref(t)); }
That's getting a bit artificial now. What is the purpose of foo1 except to break the code?
The point was that (a) unwrap_reference doesn't remove all nested levels of reference_wrappers, just the top level, so class_type does not have bar when foo1 is called and (b) boost::bind saves a reference to a reference, so get_pointer does not work as intended, not to mention that a dangling reference may be left if the function object call is delayed.
If you delay the function call in
template< typename T > void foo(T const& t) { typedef typename boost::unwrap_reference<T>::type class_type; boost::bind(&class_type::bar, boost::ref(t))(); }
it will result in a dangling reference when called with an rvalue of any type. This line, for example:
foo(my_class_const());
will store a dangling reference to the my_class_const temporary.