0

Why does this work?

set <pair<int, int>> prevIslands;

While this does not:

unordered_set <pair<int, int>> prevIslands;

And gives the error:

required from 'struct std::__and_<std::__is_fast_hash<std::hash<std::pair<int, int> > >, std::__detail::__is_noexcept_hash<std::pair<int, int>, std::hash<std::pair<int, int> > > >'

Do set and unordered_set have different requirements from the underlying container object?

abhinav.mehra
  • 125
  • 1
  • 1
  • 7
  • 2
    `unordered_set` requires that there is a hash function for the item type. As I recall g++ and MSVC used to differ in what types their standard library implementations provided hashing for, with g++ deficient in its support for `enum` types. I'm not sure what precisely the standard requires, but you can just write a hashing function for any type you want to use. – Cheers and hth. - Alf Aug 18 '18 at 01:51
  • A simple hash for a tuple is to xor together the hashes for the individual tuple components. – Cheers and hth. - Alf Aug 18 '18 at 01:59
  • [You need to supply the additional template arguments](https://en.cppreference.com/w/cpp/container/unordered_set) to `unordered_set` for your code to compile. – PaulMcKenzie Aug 18 '18 at 02:01
  • For a better understanding, see the differences between them: https://stackoverflow.com/questions/16075890/what-is-the-difference-between-set-and-unordered-set-in-c – arorias Aug 18 '18 at 02:03

0 Answers0