无法排序unordered

编程入门 行业动态 更新时间:2024-10-09 12:32:34
本文介绍了无法排序unordered_set的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个类别为ActiveStatusEffect的unordered_set该集合声明如下:

I have an unordered_set of a class ActiveStatusEffect The set is declared as follows:

boost::unordered_set<StatusEffects::ActiveStatusEffect> ActiveStatusEffects;

ActiveStatusEffect定义如下:

ActiveStatusEffect is defined as follows:

class ActiveStatusEffect { public: StatusEffect* effect; int ReminaingTurns; bool operator<(const ActiveStatusEffect& ase) const { return *effect < *ase.effect; } bool operator>(const ActiveStatusEffect& ase) const { return *effect > *ase.effect; } bool operator==(const ActiveStatusEffect& ase) const { return *effect == *ase.effect; } bool operator!=(const ActiveStatusEffect& ase) const { return !((*this) == ase); } };

StatusEffect之间的比较是对分配给状态效果的每个实例的唯一整数之间的比较.

The comparison between StatusEffect's is a comparison between a unique integer assinged to each instance of a status effect.

但是,如果我尝试对效果进行排序,如下所示:

However, if I try to sort the effects like follows:

std::sort(statusSet.begin(), statusSet.end(), [](StatusEffects::ActiveStatusEffect const &se1, StatusEffects::ActiveStatusEffect const &se2){return se1.effect->GetPriority() < se2.effect->GetPriority();});

我在算法头文件中遇到很多错误,例如

I get many errors in the algorithm header file such as

错误198错误C2784: '_Base1 :: difference_type std :: operator -(const std :: _ Revranit< _RanIt,_Base>&,const std :: _ Revranit< _RanIt2,_Base2> &)':无法推断出模板 'const的参数 std :: __ Revranit< _RanIt,_Base>&'从 'boost :: unordered_detail :: hash_const_iterator'c:\ program 文件(x86)\ Microsoft Visual Studio 10.0 \ vc \ include \ algorithm 3806

Error 198 error C2784: '_Base1::difference_type std::operator -(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'boost::unordered_detail::hash_const_iterator' c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm 3806

错误199错误C2784: '_Base1 :: difference_type std :: operator -(const std :: _ Revranit< _RanIt,_Base>&,const std :: _ Revranit< _RanIt2,_Base2> &)':无法推断出模板 'const的参数 std :: __ Revranit< _RanIt,_Base>&'从 'boost :: unordered_detail :: hash_const_iterator'c:\ program 文件(x86)\ Microsoft Visual Studio 10.0 \ vc \ include \ algorithm 3806

Error 199 error C2784: '_Base1::difference_type std::operator -(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'boost::unordered_detail::hash_const_iterator' c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm 3806

为什么我不能对集合进行排序?我敢肯定,这与unordered_set有关,因为删除尝试将其排序或更改为向量不会产生错误.

Why am I not able to sort the set? I'm quite certain this is something about unordered_set as removing attempts to sort or changing it to a vector does not generate errors.

推荐答案

boost::unordered_set<Foo> a; a.insert(...); ... std::set<Foo> b(a.begin(), a.end()); std::set<Foo> c; std::copy(a.begin(), a.end(), std::inserter(c, c.end());

Voilà,已排序的集合.

Voilà, a sorted set.

更多推荐

无法排序unordered

本文发布于:2023-11-29 01:50:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1644816.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:unordered

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!