提问人: 提问时间:5/12/2014 最后编辑:Community 更新时间:5/17/2014 访问量:593
比较 connection_hdl (weak_ptr) 的相等性
Compare connection_hdl (weak_ptr) for equality
问:
我需要比较两个 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)));
我试过这个代码
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);
}
但编译器抱怨.connection_hdl is not a template
上面的代码可以修改以比较connection_hdls吗?connection_hdls可以通过使用owner_less与容器一起使用,因此以我的经验,所有权可用于比较是有道理的。
我能找到的唯一其他相关技术是比较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()));
这似乎很接近我的需求,但由于我缺乏经验,我无法确定或修改该代码以适应我的意图。
如何比较两个connection_hdls的平等性?
这安全吗?
我将第一个代码修改为这个
bool connections_equal(connection_hdl t, connection_hdl u)
{
return !t.owner_before(u) && !u.owner_before(t);
}
它编译。除了weak_ptr空虚警告之外,这安全吗?我缺乏经验使我无法准确确定,而我有限的经验告诉我,仅仅因为它编译,并不意味着它会按预期工作。
答: 暂无答案
评论