Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

operator-> for reference_wrapper #94

Open
denzor200 opened this issue Aug 2, 2021 · 3 comments
Open

operator-> for reference_wrapper #94

denzor200 opened this issue Aug 2, 2021 · 3 comments

Comments

@denzor200
Copy link

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

@Lastique
Copy link
Member

Lastique commented Aug 3, 2021

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

@pdimov
Copy link
Member

pdimov commented Aug 3, 2021

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
Copy link
Member

pdimov commented Aug 3, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants