I need to compare two websocket++ connection_hdl:
// Create a weak pointer on the heap using that shared_ptr.
// Cast that weak pointer to void* and manage it using another shared_ptr
// connection_hdl hdl(reinterpret_cast<void*>(new connection_weak_ptr(con)));
I tried this code
template <typename T, typename U>
inline bool equals(const connection_hdl<T>& t, const connection_hdl<U>& u)
{
return !t.owner_before(u) && !u.owner_before(t);
}
but the compiler complains that connection_hdl is not a template
.
Can the above code be modified to compare connection_hdls? connection_hdls can be used with containers by using owner_less, so in my inexperience it stands to reason that ownership could be used for comparison.
The only other related technique I can find is for comparing sets of weak_ptrs
bool result = !(std::lexicographical_compare(set1.begin(), set1.end(),
set2.begin(), set2.end(),
set1.value_comp()) ||
std::lexicographical_compare(set2.begin(), set2.end(),
set1.begin(), set1.end(),
set1.value_comp()));
which seems to be close to my needs, but I can't be sure or rework that code to suit my intent because of my inexperience.
How can two connection_hdls be compared for equality?
is this safe?
I modified the first code to this
bool connections_equal(connection_hdl t, connection_hdl u)
{
return !t.owner_before(u) && !u.owner_before(t);
}
and it compiles. Is this safe aside from the weak_ptr emptiness caveat? My inexperience prevents me from determining exactly while my limited experience tells me that just because it compiles, doesn't mean it will work as expected.