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

const version of proxy::invoke() #24

Closed
misirlou-tg opened this issue Aug 21, 2022 · 1 comment
Closed

const version of proxy::invoke() #24

misirlou-tg opened this issue Aug 21, 2022 · 1 comment

Comments

@misirlou-tg
Copy link

I was experimenting with this library using the sample code in the recent C++ Team Blog. I wanted to make multiple methods that operated on the same proxy so I did something like the following:

DoSomething1(const pro::proxy<Facade> &p) {
    p.invoke<dispatch1>();
}

But this won't compile because invoke() is non-const. Casting away the const works of course. Making the parameter non-const is not desirable because of the problem passing in temporary values.

@mingxwa
Copy link
Collaborator

mingxwa commented Aug 22, 2022

Duplicate: #22

This is by design. Because proxy does not require P::operator* to be const, where P is the type of a potential contained value, proxy::invoke() is designed to be non-const.

Regarding your scenario, if you want to "make multiple methods that operated on the same proxy",

  1. it is encouraged to pass parameters by pointer,
  2. you may configure the proxy to be copyable by specifying minimum_copyability in you facade definition, so that you can pass the proxy by value, like arbitrary pointers, but your proxy will not accept non-copyable pointers, like std::unique_ptr, any longer.

Thank you for you comments! Please let us know if you have any further questions or suggestions!

@mingxwa mingxwa closed this as not planned Won't fix, can't repro, duplicate, stale Aug 25, 2022
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

2 participants