我想创建一个使用boost :: multi_index的URL管理对象。它有2个索引,每个路径项目的一个索引位置和一个索引键来查找该项目。Boost multi_index unqiue索引问题
class InternalPath
{
public:
struct PathItem
{
int Position;
std::string Key;
std::string Path;
};
typedef boost::multi_index_container<
PathItem,
boost::multi_index::indexed_by<
boost::multi_index::ordered_unique<boost::multi_index::member<PathItem,int,&PathItem::Position>>,
boost::multi_index::ordered_unique<boost::multi_index::member<PathItem,std::string,&PathItem::Key>>
>
> PathContainer;
private:
PathContainer path_;
};
但是,有一个问题,并非所有的项目都有它的关键。大多数项目只包含位置和路径。我希望钥匙是独一无二的。现在,当我插入多个非关键项目时会出现问题。
是否可以允许具有空字符串的键在容器中具有多个项目。如果不是,我该怎么做才能克服这个问题?
问:是否有可能在唯一索引中有重复键? - 答:号 –