title: How to make std::map compare to work on multiple data types?
body: <p>I've a entire table stored in <code>std::deque&lt;record *&gt;</code> and I need to allow the user to sort the table on any column. The table is presented to the user in a list box format.</p>
  
  <p>Each record consists of multiple strings (struct of strings). However, the fields are of different types i.e., time (HH:MM:SS), float, and strings, even though they are all stored as strings.</p>
  
  <p>The user is permitted to sort on any of these columns. When the user clicks on the column, I store each record in a multimap so that the table is shown in sorted format to the user.</p>
  
  <p>However, since the columns are of different types, how do I write a single compare method, that handles all these efficiently?</p>
  
  <p>I thought of the following ways</p>
  
  <ol>
  <li>Use different maps for each type and write one compare function class for each of the maps.</li>
  <li>Use a single map, with a compare class that handles all three different types. But for each insertion, the comparison class has to decide the type , and insert accordingly. </li>
  </ol>
  
  <p>Is there a better way than these two?</p>
  
  <p>Example:</p>
  
  <pre><code>struct ltDataCompare
  {
  
      bool operator()( const CString&amp; csData1, const CString&amp; csData2)  const
      {
  
          if ( isTimeFormat(csData1) &amp;&amp; isTimeFormat(csData1) )
          {
                 // Do time relevant comparision
              }
              else if ( isNumberFormat( csTime1 ) &amp;&amp; isNumberFormat(csTime2) )
          {
              double dPrice1 = atof((LPCTSTR)csTime1);
              double dPrice2 = atof((LPCTSTR)csTime2);
  
              return ( dPrice1 &lt; dPrice2);
          }
          return ( csTime1 &lt; csTime2 );
      }
  };
  
  std::multimap&lt;CString,list_record_t*,ltDataCompare&gt; _mapAllRecords; // Used only for sorting
  </code></pre>