【发布时间】:2012-12-19 19:31:20
【问题描述】:
我正在尝试使用 GCC 4.7.2 比较两组 C++11 weak_ptr。下面的代码显示了重现错误的最小可能示例:
std::set<std::weak_ptr<int>, std::owner_less<std::weak_ptr<int> > > set1;
std::set<std::weak_ptr<int>, std::owner_less<std::weak_ptr<int> > > set2;
bool result = (set1 == set2);
试图编译上面的结果会导致一长串错误,其中以下是第一个实际错误:
/usr/include/c++/4.7/bits/stl_algobase.h:791:6: error: no match for ‘operator==’ in ‘__first1.std::_Rb_tree_const_iterator<_Tp>::operator*<std::weak_ptr<int> >() == __first2.std::_Rb_tree_const_iterator<_Tp>::operator*<std::weak_ptr<int> >()’
由于weak_ptr 的瞬态特性,是否无法比较它们的整个集合?
更新:
一个建议是使用:
bool result = !((set1 < set2) || (set2 < set1))
这会导致:
/usr/include/c++/4.7/bits/stl_algobase.h:882:6: error: no match for ‘operator<’ in ‘__first1.std::_Rb_tree_const_iterator<_Tp>::operator*<std::weak_ptr<int> >() < __first2.std::_Rb_tree_const_iterator<_Tp>::operator*<std::weak_ptr<int> >()’
【问题讨论】:
标签: c++ c++11 compare std stdset