title: Custom map with C++
body: <p>I want to create a custom map. I don't want to compare the key, I want the second element on map, I don't really know how to explain this so here is some code I have written which will hopefully explain what I want:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;map&gt;
  
  struct box {
      int size, color, price, position;
  };
  
  struct custom_compare {
      bool operator()(const box&amp; lhs, const box&amp; rhs) const {
          if(lhs.size  != rhs.size)  return lhs.size &lt; rhs.size;
          if(lhs.color != rhs.color) return lhs.color &lt; rhs.color;
          if(lhs.price != rhs.price) return lhs.price &lt; rhs.price;
          return lhs.position &lt; rhs.position;
      }
  };
  
  int main() {                   //here, box isn't the key
      std::map&lt;std::string, box, custom_compare&gt; box_map;
      box_map["my box"] = {1,5,200,1};
      box_map["jose's box"] = {3,1,300,2};
      box_map["maria's box"] = {2,4,100,3};
      // The problem is that the custom_compare get 'box_map.first', not 'box_map.second'
      // I wish map compare struct box, not string
  }
  </code></pre>
  
  <p>I can't put the struct on key, I need the associativity.  </p>
  
  <p>So, is there a way to custom compare a map based on the second element(not the key)?</p>