2

I want to create a tuple/array like (0,1,2), (3,4,5). I want to store it into an unordered_set. But unordered_set didn't offer such a hash function. Can anyone tell me how can I do this?

I have read thes answer: C++ how to insert array into hash set? but I don't want to add any extra code like hash function.

Community
  • 1
  • 1
maple
  • 1,828
  • 2
  • 19
  • 28
  • There is no alternative but to add a hash function. Because std libraries don't provide the hash function for tuple and arrays. You can create your own templatized hash class which can be reused. – Mohit Jain May 20 '16 at 10:44

1 Answers1

1
  1. I want to store [array] into an unordered_set

  2. unordered_set didn't offer such a hash function

  3. I don't want to add any extra code like hash function.

Tough luck. A hash function is mandatory. Since it's not provided by the standard library, it must be provided by you. The answer in the question you linked shows how to write a hash function for std::array.

Community
  • 1
  • 1
eerorika
  • 232,697
  • 12
  • 197
  • 326