IKM C++ assessment asks about std::unordered_set, part #1 Recently I had to do an IKM C++ assessment to qualify for a job. Some of the questions seemed strange to me, so I'll be doing a few posts here to discuss.
The first one is related to use of std::unordered_set. From what I remember it went something like:

A programmer is using a struct to contain some data. The struct must be stored in a std::unordered_set. True or false: The structure has to overload the method operator==() in order for the structure to be supported by std::unordered_set?

I wrote a test program to demonstrate:
#include &lt;iostream&gt;
#include &lt;random&gt;
#include &lt;unordered_set&gt;

struct ikm_test_struct {

   size_t m1;
   
   std::size_t operator()(ikm_test_struct const&amp; s) const noexcept;  
   
   constexpr bool operator==(const ikm_test_struct &amp;rhs) const;
};

// Method operator() must return a size_t so use its limits in our distribution.

std::uniform_int_distribution&lt;&gt; distrib(
   std::numeric_limits&lt;std::size_t&gt;::min(),
   std::numeric_limits&lt;std::size_t&gt;::max()
);

std::size_t ikm_test_struct::operator()(ikm_test_struct const&amp; s) const noexcept {

   // Seed a random number generator using the value in the parameter struct.
    
   std::mt19937 gen(s.m1);
    
   // Exercise the random number generator so that it is well away from any less random starting values.

   for (size_t i = 0; i &lt; 100; ++i) distrib(gen);
    
   // Generate a random number in the required range.
    
   return distrib(gen);
}

constexpr bool ikm_test_struct::operator==(const ikm_test_struct &amp;rhs) const {
   return m1 == rhs.m1;
}

typedef std::unordered_set&lt;ikm_test_struct, ikm_test_struct&gt; ikm_test_unordered_set;

int main()
{      
   ikm_test_unordered_set x;
   
   for (size_t i = 0; i &lt; 100; ++i) {
   
      ikm_test_struct y;
      y.m1 = i;
      
      x.insert(y);
   }
   
   size_t j = 0;
   for (const auto&amp; k: x) {
      std::cout &lt;&lt; &quot;x[&quot; &lt;&lt; j &lt;&lt; &quot;] = &quot; &lt;&lt; k.m1 &lt;&lt; std::endl;
      ++j;
   }
}

So it is possible to write a structure that implements operator==() and is then used in a std::unordered_set. Given this demonstration how should we answer the original question:

The demo code proves that it is possible to do this but the question says &quot;has to overload the method operator==()&quot;. There are other ways to implement an equality test. Like creating a separate class or struct and using that class as the third parameter on the std::unordered_set template. So do you answer the question yes because it is possible or no because you don't have to do it that way?
The question says &quot;has to overload&quot;. But the demo code implements operator==() only once, so there is no &quot;overloading&quot; of this method. If there is no overloading should the question be answered false? That seems to miss the point of asking the question to test your C++ knowledge.
The question says &quot;in order for the structure to be supported&quot;. &quot;Supported&quot; is kind of ambiguous. Supported how, with what specialization of std::unordered_set, with what other helper classes?

Given the above it seems that the question is one that has no correct answer. Therefore, it is stupid to include it in a test that is supposed to evaluate someones C++ skills.
What do you think?
Defining an operator== for your own type is overloading.  The overload set includes all the built-in signatures.
Based on how you worded it, I agree with (1).  It is not true that you must define operator== for that struct in order to use it with std::unordered_set.  You can use the template argument, or you can cause the default predicate to work in other ways especially in newer versions of C++ (e.g. default the spaceship operator).
As for the example, doesn't it also need to specialize std::hash in order for it to work?  std::unordered_set&lt;ikm_test_struct, ikm_test_struct&gt; doesn't make sense.
If this test is going to be read by other prospective team members, then essaying what you thought is going to communicate to them that you (1) know your stuff; and (2) will be likely to apply the same skill to interpreting requirements.  Finish by correcting the sloppy nomenclature, linking to cppreference and/or a copy of the Standard, and reviewing the code of the sample (with citations to the Standard Guidelines).
If you're passed on as &quot;overqualified&quot;, you'll be glad in the long run.
If it's a multiple-choice computer-based thing that just reports the score, that can be a real pain.  I recall encountering one where the expected results were sometimes just plain wrong, or out of date, or the question was worded poorly.  You should contact the people who made the test.