Open lotodore opened 9 years ago
Please note: This works fine with an older release (< 0.5.0) of websocket++ (with the current android ndk).
If the solution is to use std::owner_less, I'd generelly consider this a bad idea. If the handles are weak_ptrs (I hope they are not, but it looks like they are :-) ), then the ordering value will basically change once the pointer is no longer valid. I do not think that this is what anyone wants to happen in a mapping of handles.
connection_hdl
is and has always been a weak pointer. std::owner_less
orders by the address of the shared pointer control block, not the address pointed to by the shared pointer. The address of the control block is stable and valid as long as at least one weak pointer remains. If you have a connection_hdl then you are guaranteed to have at least one weak pointer. This also ensures that connection_hdl's never overlap, overflow, or recycle until the prior user of that address is done with it.
Prior to 0.5.0 WebSocket++ used boost::weak_pointer
by default and std::weak_pointer
only if a special C++11 mode flag was defined. Starting in 0.5.0, C++11 library availability is automatically detected on most popular platforms when the -std=c++0x/11
or later language dialect is selected. There are some more exotic compilers and platforms that cannot be autodetected and may fall back to boost unless C++11 mode is explicitly turned on.
I should probably look into seeing if there is a way for the library to explicitly supply comparison operators for cases when std::weak_pointer
is used so end users don't have to define this themselves and the transition between boost and std based connection_hdls is more smooth.
OK sorry, I was obviously wrong about std::owner_less with weak_ptr. I did not know it behaves that way, feels somehow counter-intuitive to its name. We'll try to solve the problem using owner_less, but still, I think this is unecessary complexity. The user of the lib should not need to know that connection_hdl is a weak_ptr and it should work with normal STL containers. Even a native FILE handle does that...
We are using connection_hdl in a map as follows:
Usually this works fine, but with the (current) android ndk (gcc 4.8) this causes a build error:
--snip--
--snip--
It should not be necessary to declare our own comparison operator because one should be able to use a handle as kind of id which implies using it as key in a mapping. With all other environments we have available (even older compilers), this seems to work fine.