struct as key of unordered_map
<p>I have a problem putting data into an unordered_map using a struct as key:</p>

<pre><code>
typedef struct osdpi_flow_identificator {
 u32 lower_ip;
 u32 upper_ip;
 u16 lower_port;
 u16 upper_port;
 u8 protocol;
} osdpi_flow_identificator_t;

// custom hash function for osdpi_flow_identificator
struct osdpi_flow_hash {
 std::size_t operator() (osdpi_flow_identificator * key) const {
  hash hash_function;
  std::size_t returnValue =
   hash_function(key->lower_ip)
   + hash_function(key->upper_ip)
   + hash_function(key->lower_port)
   + hash_function(key->upper_port)
   + hash_function(key->protocol);

  printf(" calculated hash: %i\n", returnValue);

  return returnValue;
 }
};

typedef unordered_map &lt;osdpi_flow_identificator*, osdpi_flow*, osdpi_flow_hash&gt; osdpi_flows_hashmap;
typedef osdpi_flows_hashmap::value_type osdpi_flows_pair;
static osdpi_flows_hashmap osdpi_flows;
</code></pre>

<p>My problem is that the hash function returns the same value for osdpi_flow_identificators having the same value, but</p>

<pre><code>
 osdpi_flow_identificator * flow_id = new osdpi_flow_identificator;
 osdpi_flows_hashmap::const_iterator iter;
 iter = osdpi_flows.find(flow_id);
 if (iter != osdpi_flows.end()) {
  ...
</code></pre>

<p>doesn't find it, although an entry with a flow_id having exactly the same values, is already in the hash map. I verified it, by outputting the whole hash map and also the hash function prints out the same value. So it's quite hard for me to understand, why unordered_map can't find the entry with the same hash.</p>

<p>I also tried to overload operator== and operator&lt;, which I sometimes found as tip in the net, but those functions also were not called.</p>

<p>What solves the issue, but, of course, later ends up with a segmentation fault, is to leave flow_id uninitialized - then the entry can be found correctly.</p>

<p>Any help is appreciated!</p>

<p>Thanks
Steffen</p>
