how to compare two std::set?

前端 未结 4 1983
一向
一向 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:16

    Another way would be this:

    template
    
    bool set_compare(Set const &lhs, Set const &rhs){
        return lhs.size() == rhs.size() 
            && equal(lhs.begin(), lhs.end(), rhs.begin());
    }
    

    Inspired from the elegant answer here.

提交回复
热议问题