Element requirements in std :: unordered_set

std::unordered_set<my_type> my_set; 

What requirements should my_type fulfill here? (In addition to specializing for std :: hash)

+6
source share
1 answer

You need specialization for std :: hash, and you need the == operator, designed to handle hash collisions.

EDIT: You must also ensure that your type has a copy constructor (or let the compiler generate it for you), since STL containers have semantics of values.

EDIT2: as an example of how to do this, you can check out this other SO answer .

+7
source

Source: https://habr.com/ru/post/911943/


All Articles