You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Why boost::reference_wrapper template class dosn't has operator-> overloading? Is there any objective reason?
It may be useful for some instantiations, like boost::reference_wrapper<Object*> or like boost::reference_wrapper<std::shared_ptr<Object>> to use these without casting
I suspect you're misunderstanding the request as T* operator-> whereas it's T& operator->.
reference_wrapper<T> is intended to act as a reference to T and has an implicit conversion operator T&, which enables this. It also has a forwarding operator() because the conversion doesn't work in this case. The request makes sense, the reason for not having operator-> is because nobody brought it up until now.
Activity
Lastique commentedon Aug 3, 2021
I suppose, the main reason is that
reference_wrapper<T>is not intended to be a proxy forT.pdimov commentedon Aug 3, 2021
I suspect you're misunderstanding the request as
T* operator->whereas it'sT& operator->.reference_wrapper<T>is intended to act as a reference toTand has an implicit conversionoperator T&, which enables this. It also has a forwardingoperator()because the conversion doesn't work in this case. The request makes sense, the reason for not havingoperator->is because nobody brought it up until now.pdimov commentedon Aug 3, 2021
E.g. https://godbolt.org/z/3zx9YbY44