我有以下代码:
wxString getColorName(const wxColour& color)
{
typedef ColorComboBox::ColorMap::right_const_iterator ConstColorIterator;
ColorComboBox::ColorMap colorMap = ColorComboBox::getDefaultChoices();
ConstColorIterator it = colorMap.right.find(color);
return it != colorMap.right.end() ? it->second :
ColorComboBox::CUSTOM_COLOR;
}其中定义了ColorMap
typedef boost::bimaps::bimap \
<wxString, boost::bimaps::vector_of<wxColour> > \
ColorMap;我一直得到一个很长的模板错误,基本上说查找函数不存在。然而,
ColorMap::left_const_iterator it = choices_.left.find(GetValue());编译得很好。
我有预感,查找函数只在特定的bimap集合类型中定义。我不能使用set_of wxColours,因为wxColour是不可比拟的。(这意味着什么?)我还尝试将集合类型更改为list_of,但这也不起作用。我使用bimap的全部目的是让我能够找到任何方向的价值。我用错容器了吗?是否有另一种可以用于wxColour的集合类型允许我使用查找函数?
编辑:我最终创建了自己的容器类。
发布于 2012-02-06 09:42:02
Bimap允许您定义每一方的映射类型。如果您的应用程序需要执行快速搜索,请使用map/multimap或unordered_map/unordered_multimap的映射。请阅读文档,并记住每个地图视图都是按照等效的STL容器建模的,因此它们共享相同的约束和接口:
set_of (有序的,唯一的)-> std::mapmultiset_of (有序)-> std::multimapunordered_set_of (散列,唯一)-> std::unordered_mapunordered_multiset_of (散列)-> std::unordered_multimaplist_of (测序)-> list_map ( std::list<pair> )vector_of (随机存取)-> vector_map ( std::vector<pair> )unconstrained_set_of -->未映射我不明白为什么选择vector_of<wxColour>,也许是因为set_of<wxColour> (默认的)没有编译.在这种情况下,正如您所说的,您需要定义自己的比较运算符来告诉bimap如何订购这些项。向量映射和列表映射允许您创建维护关系插入顺序的bimaps。
在你的例子中,你想要的是一个unordered_set_of。您需要为wxColour定义自己的散列函式。您可以使用Boost.Hash来实现它。
诚挚的问候
https://stackoverflow.com/questions/9140559
复制相似问题