Hi! I'm getting started with capnp, using C++ bindings (with C++17 compiled 
by Clang 12.) I'm having trouble storing remote object references, i.e. 
xx::Client objects, in STL collections. For example:

std::map<string,Foobar::Client> foobars;
...
Foobar::Client c = promise.wait(waitScope).getFoobar();
foobars.insert({name, c});    // Compile error

The error is "*the parameter for this explicitly-defaulted copy constructor 
is const, but a member or base requires it to be non-const*."

I eventually worked out that the error is because *Client's copy 
constructor takes a `Client&` parameter, i.e. requires a mutable reference, 
which breaks the std::pair class* because it needs to be able to copy a 
const reference. And if you can't put a client into a std::pair, you can't 
put it into a std::map or std::unordered_map.

I assume there must be a reason for leaving out the standard `const` in the 
copy constructor's parameter; but I can't work out what it would be. I know 
Client objects are wrappers for a pointer to a ref-counted value, so 
copy-constructing one bumps the value's ref-count, but that value is a 
separate object so it shouldn't matter whether the Client reference is 
const or not. (FYI, I've implemented my own ref-counted objects in C++ so 
I'm pretty familiar with the details...)

Is there a good workaround for storing RPC client objects in STL maps? 
Thanks!

--Jens

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to capnproto+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/capnproto/63af6853-ac43-4c75-a161-a4c939199e93n%40googlegroups.com.

Reply via email to