4

I have a bimap. I want to check if key exists in my bimap. How can i do that. Here is my 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;
            }

I want to check if 'Name' is exists.

kebs
  • 6,387
  • 4
  • 41
  • 70
Seçkin Durgay
  • 2,758
  • 4
  • 27
  • 36

1 Answers1

8

This is explained quite clearly in this example. In your case, it should look like this:

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
}
Björn Pollex
  • 75,346
  • 28
  • 201
  • 283
  • 1
    The `find()` function belongs to the collection type used when defining the map type. In this example, it's `set_of`, which is documented [here](http://www.boost.org/doc/libs/release/libs/bimap/doc/html/boost_bimap/reference/set_of_reference.html). – Björn Pollex Jun 10 '16 at 09:16