How can I use a C++ unordered_set for a custom class?
<p>How can I store objects of a class in an <code>unordered_set</code>? My program needs to frequently check if an object exists in this <code>unordered_set</code> and if it does, then do some update on that object.</p>

<p>I have looked up online on how to use <code>unordered_set</code>, but sadly most tutorials are about using it on <code>int</code> or <code>string</code> types. But how can I use it on a class? How can I define a hash function to make the <code>node_id</code> in the following example the key of the <code>unordered_set</code>?</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;unordered_set&gt;

using namespace std;

// How can I define a hash function that makes 'node' use 'node_id' as key?    
struct node
{
    string node_id;
    double value;
    node(string id, double val) : node_id(id), value(val) {}
};

int main()
{
    unordered_set&lt;node&gt; set;
    set.insert(node("1001", 100));
    if(set.find("1001") != set.end()) cout &lt;&lt; "1001 found" &lt;&lt; endl;
}
</code></pre>