Can set_intersection be used with hash_set in C++?

后端 未结 3 1461
遇见更好的自我
遇见更好的自我 2021-01-22 03:09

I am calculating intersection, union and differences of sets. I have a typedef of my set type:

typedef set node_set;

When it i

3条回答
  •  自闭症患者
    2021-01-22 03:28

    I don't think so.

    One of the pre-condition of set_intersection is:

    • [first1, last1) is ordered in ascending order according to operator<. That is, for every pair of iterators i and j in [first1, last1) such that i precedes j, *j < *i is false.

    The hash_set (and unordered_set) is unordered, so the ordered condition cannot be satisfied.

    See tr1::unordered_set union and intersection on how to intersect unordered_sets.

提交回复
热议问题