2012-04-05 6 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; 
      } 

'이름'이 존재하는지 확인하고 싶습니다.

답변

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

감사합니다. –

+1

'find()'함수는 어디에 문서화되어 있습니까? 부스트 문서가 엉망입니다! – DBedrenko

+0

'find()'함수는 맵 타입을 정의 할 때 사용 된 콜렉션 타입에 속한다. 이 예제에서는'set_of'가 있습니다. [here] (http://www.boost.org/doc/libs/release/libs/bimap/doc/html/boost_bimap/reference/set_of_reference.html)에 설명되어 있습니다. –

관련 문제