Checking whether an element exist or not in the map within map

前端 未结 5 954
庸人自扰
庸人自扰 2021-01-24 22:07

I have a map of the form map > :

For Example: I am storing the intensity value at 2-D co-ordinate(x,y) i

5条回答
  •  野性不改
    2021-01-24 22:26

    This is bit ugly but should work too : (using C++11)

    std::map > intensityValue;
    int x,y;
    auto it = std::find_if(intensityValue.begin(),
                        intensityValue.end(),
                        [x,y](const std::pair>& p){
                          return p.first==x && 
                                 p.second.find(y) !=p.second.end();
                        }
                        );
    
      if(it != intensityValue.end())
      {
          //Got it !
      } 
    

提交回复
热议问题