Inside boost there's boost::detail::addr_impl_ref struct that basically has a constructor accepting a T&
reference and an overloaded operator T&()
that returns that reference. It is used in the implementation of boost::addressof():
template<class T> T* addressof( T& v )
{
return boost::detail::addressof_impl<T>::f( boost::detail::addr_impl_ref<T>( v ), 0 );
}
boost::detail::addressof_impl<T>::f()
accepts T&
as the first parameter. boost::addressof<T>()
also has T& v
as the parameter.
Why is boost::detail::addr_impl_ref()
temporary object used here to store and return T&
instead of just passing T& v
?