0

unordered_set<vector<int>> my_set;

I am using xcode for c++ development and I came across a wired error. When I declared a unordered_set with the generic of vector<int>, I got an error, saying:

Call to implicitly-deleted default constructor of '__compressed_pair_elem<std::__1::hash<std::__1::vector<int, std::__1::allocator > >, 1>'

I tried unordered_set<vector<int>>.

I tried similar stuff like unordered_set<int>, unordered_set<vector<int>*>, set<vector<int>>, and all of them works out fine. What is wrong with unordered_set<vector<int>>?

I was a java developer and am transferring to c++ recently. So my logic might still be a little bit of "java"...

Evg
  • 25,259
  • 5
  • 41
  • 83
sbgbbt
  • 23
  • 5
  • 1
    Make sure you look at the full error message. Mine comes with a [descriptive static assertion](https://gcc.godbolt.org/z/ToK4Pz). – chris Aug 03 '20 at 07:00
  • 2
    To be explicit, you need a hash function for `T` in order to use it in `unordered_set`. Clearly `vector` does not have a hash function by default, so you must supply one. All of the collection classes make some requirements on their value types, and this is one example. – john Aug 03 '20 at 07:04
  • Just calling a template a generic is proof of your Java background. Although the purpose is similar the design is totally different. – john Aug 03 '20 at 07:05

0 Answers0