How to check that an element is in a std::set?

前端 未结 10 1976
春和景丽
春和景丽 2020-11-30 17:13

How do you check that an element is in a set?

Is there a simpler equivalent of the following code:

myset.find(x) != myset.end()
10条回答
  •  爱一瞬间的悲伤
    2020-11-30 17:28

    Write your own:

    template
    bool checkElementIsInSet(const T& elem, const std::set& container)
    {
      return container.find(elem) != container.end();
    }
    

提交回复
热议问题