How do I find the largest int in a std::set?

后端 未结 5 1485
深忆病人
深忆病人 2021-02-03 17:19

I have a std::set, what\'s the proper way to find the largest int in this set?

5条回答
  •  伪装坚强ぢ
    2021-02-03 17:29

    What comparator are you using?

    For the default this will work:

    if(!myset.empty())
        *myset.rbegin();
    else
        //the set is empty
    

    This will also be constant time instead of linear like the max_element solution.

提交回复
热议问题