2012-04-05 96 views
3

我有一个bimap。我想检查一下密钥是否存在于我的bimap中。我怎样才能做到这一点。这是我的bimap:Cpp - 检查增强bimap中是否存在密钥

namespace bimap 
      { 

       struct Name{}; 
       struct ID{}; 

       typedef 
        boost::bimaps::bimap< 
         boost::bimaps::set_of< 
          boost::bimaps::tagged< 
           unsigned short 
           , ID 
          > 
         >, 

         boost::bimaps::set_of< 
           boost::bimaps::tagged< 
           std::string 
           , Name 
          > 
         > 
        > 
        name_index_bimap; 
      } 

我想检查'Name'是否存在。

回答

6

这在this example中有相当清楚的解释。在你的情况下,它应该看起来像这样:

name_index_map your_map; 
name_index_map::right_const_iterator it = your_map.by<Name>().find("some name"); 
if(it == your_map.right.end()) { 
    // name does not exists 
} 
+0

非常感谢 – 2012-04-05 07:16:28

+1

find()函数在哪里记录?提升文档是一团糟! – DBedrenko 2016-06-10 09:10:15

+0

find()函数属于定义地图类型时使用的集合类型。在这个例子中,它是'set_of',这是记录[这里](http://www.boost.org/doc/libs/release/libs/bimap/doc/html/boost_bimap/reference/set_of_reference.html)。 – 2016-06-10 09:16:02