core icon indicating copy to clipboard operation
core copied to clipboard

operator-> for reference_wrapper

Open denzor200 opened this issue 4 years ago • 3 comments

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

denzor200 avatar Aug 02 '21 23:08 denzor200

I suppose, the main reason is that reference_wrapper<T> is not intended to be a proxy for T.

Lastique avatar Aug 03 '21 00:08 Lastique

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.

pdimov avatar Aug 03 '21 06:08 pdimov

E.g. https://godbolt.org/z/3zx9YbY44

pdimov avatar Aug 03 '21 06:08 pdimov