title: Using a map with a non-trivial key type
body: <p>I have a trouble implementing a map with a non-trivial key type. Originally, I needed a map, which would use GUID type as the key:</p>
  
  <pre><code>std::map&lt;GUID, int&gt;
  </code></pre>
  
  <p>Since compiler does not know how to compare GUIDs, I chose the following approach to resolve the problem. Let’s have a wrapper around GUID in the following manner:</p>
  
  <pre><code>class MyGUID
  {
  
  public:
  
  MyGUID(const GUID&amp; _guid) : m_guid(_guid) {}
  
  bool operator &lt;(const MyGUID&amp; otherGUID) const
  {
  return m_guid.Data1 &lt; otherGUID.Data1;
  }
  
  bool operator ==(const MyGUID&amp; otherGUID) const
  {
  return m_guid.Data1 == otherGUID.Data1;
  
  }
  
  private: GUID m_guid;
  
  };
  </code></pre>
  
  <p>Obviously the above implementation of the overloaded operators is insufficient in general, but it’s good enough for the purposes of my project, where the set of possible GUIDs is predetermined and never changes.
  So, instead of my original map, I would use the following map:</p>
  
  <pre><code>std::map&lt;MyGUID, int&gt;
  </code></pre>
  
  <p>Compiler (VS2015) is perfectly happy with that, and I can populate the map without any problem:</p>
  
  <pre><code>Std::map&lt;MyGuid, int&gt; fooMap;
  GUID g1, g2;
  CLSIDFromString(“{102958f3-7578-41ca-af71-aa236a488d52}”, &amp;g1);
  CLSIDFromString(“{3c55a13d-55e1-47cc-97a3-51b3f680da79}”, &amp;g2);
  
  fooMap[g1] = 1;
  fooMap[g2] = 12;
  </code></pre>
  
  <p>The problem comes later, when I try to find the map entries by key:</p>
  
  <pre><code>fooMap.find(g1); 
  </code></pre>
  
  <p>The result is </p>
  
  <pre><code>fooMap.end()
  </code></pre>
  
  <p>According to debugger, my overloaded operators are not event executed as part of “find”. What am I doing wrong?</p>