Question

I just want to ask whether boost::bimap provides a method to find the relation in the bimap? since I have a bimap with unordered_multiset at both side, I will need a function to check whether these is a relation between two objects. I read some documentation but didnt find that.

class MyClass
{
  std::string s1;
  std::string s2;
  bool operator == (MyClass const& myClass)
  {
    return (s1 == myClass.s1 && s2 == myClass.s2);
  }
};

namespace std
{
  template<>
  struct hash<MyClass>
  {
    std::size_t operator()(const MyClass& myClass) const
    {
      std::size_t Seed = 0;
      boost::hash_combine(Seed, myClass.s1);
      boost::hash_combine(Seed, myClass.s2);
      return Seed;
    }
  }
}


int main()
{
  typedef boost::bimaps::bimap<boost::bimaps::unordered_multiset_of<client,std::hash<MyClass>, std::equal_to>, boost::bimaps::bimap<boost::bimaps::unordered_multiset_of<client,std::hash<MyClass>, std::equal_to>> MyBiMap;

  MyBiMap MAP;

  Map.value_type myRelation;
  MAP.insert(myRelation(myClassObject1,myClassObject2));
  MAP.insert(myRelation(myClassObject1,myClassObject4));
  MAP.insert(myRelation(myClassObject3,myClassObject4));
  MAP.insert(myRelation(myClassObject3,myClassObject6));
  MAP.insert(myRelation(myClassObject5,myClassObject2));
//    I want to check whether there is a relation between myClassObject1,myClassObject4
//    for example MAP.find(myRelation(myClassObject1,myClassObject4)) returns the iterator
//    and MAP.find(myRelation(myClassObject1,myClassObject6)) returns end();
    }

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top