title: Is it possible to use elements of a different type than contained in a std::set to perform search and deletion?
body: <p>Let's say I have the following:</p>
  
  <pre><code>struct MetadataThingy {
  
      void *actual_thingy;
      int some_metadata;
      int more_metadata;
  
      bool operator&lt;(MetadataThingy const&amp; other) const {
          return actual_thingy &lt; other.actual_thingy;
      }
  
  };
  </code></pre>
  
  <p>where <code>actual_thingy</code> points to some data of importance and I want the container ordered by the value of <code>actual_thingy</code> rather than the value of the element pointed at, but I need to store some other data about it, so I created the wrapper class <code>MetadataThingy</code> with a comparator that only considers the value of the <code>actual_thingy</code> pointer (rather than using a container of <code>void *</code>)</p>
  
  <p>Now, given the following code:</p>
  
  <pre><code>std::set&lt;MetadataThingy&gt; thingy_set;
  
  void test() {
  
      MetadataThingy m1 { nullptr, 5, 20 };
      MetadataThingy m2 { &amp;m1, 1, 2 };
      MetadataThingy m3 { &amp;m2, 6, 0 };
  
      thingy_set.insert(m1);
      thingy_set.insert(m2);
      thingy_set.insert(m3);
  
      MetadataThingy m;
      m = *thingy_set.find(m2); // OK.
      m = *thingy_set.find(static_cast&lt;void *&gt;(&amp;m2)); // Nope. Can't use a pointer.
  
  }
  </code></pre>
  
  <p>Since each <code>MetadataThingy</code> can be uniquely identified by the pointer value it stores and is ordered by the pointer value, it would make sense to find/delete objects simply by using a <code>void *</code> as the key. As it currently stands, though, I would have to create a dummy <code>MetadataThingy</code> each time I search for an element, which feels really kludgy. I've already considered using just a <code>map</code> with pointers as key and <code>MetadataThingy</code> as value but since each <code>MetadataThingy</code> must also contain the pointer anyway, this feels a bit redundant. So, <strong>is there a way to use an element of a type other than that stored in a set to find or delete values in the set, given that elements of the two types are mutually comparable</strong> and that elements of one type can be uniquely mapped into the other ( <code>void *</code> and <code>MetadataThingy</code> are isomorphic)? (I didn't include any in the above code, but suppose there are operator overloads for comparing <code>void *</code> and <code>MetadataThingy</code> in any order.)</p>
  
  <p>A little background on the problem I'm trying to solve, just in case anyone can recommend a better approach: I need to order a collection by multiple criteria, so I have several <code>MetadataThingy</code> containers, all sorted by different criteria. "Metadata" in this case would be stuff I need to track the positions of the elements in all containers so that I can do fast removal. This would sound like a perfect job for boost multi-index containers, but the ordering of these elements is constantly changing, which AFAIK would mean it won't work.</p>