Cpp - check if key exists in binary forcing

I have a bimap. I want to check if a key exists in my bimam. How can i do this. 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" exists.

+3


source to share


1 answer


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
}

      

+7


source







All Articles