how to compare two std::set?

前端 未结 4 1981
一向
一向 2021-02-03 18:45

I do such comparison of two std::set

#include 
#include 
using namespace std;

#include 
#include 

        
4条回答
  •  情歌与酒
    2021-02-03 19:15

    C++11 standard on == for std::set

    Others have mentioned that operator== does compare std::set contents and works, but here is a quote from the C++11 N3337 standard draft which I believe implies that.

    The quote is exactly the same as that for std::vector which I have interpreted in full detail at: C++: Comparing two vectors

    As a short summary to avoid duplication with that other answer:

    • 23.2.1 "General container requirements" states that all containers use equal() for operator==
    • 25.2.11 "Equal" defines equal and explicitly shows that it iterates over both containers comparing the elements of each

提交回复
热议问题