title: Map comparator using child element values
body: <p>I have a map that's declared by the following:</p>
  
  <pre><code>std::map&lt;std::string, std::map&lt;std::string, std::string&gt;&gt; groupList;
  </code></pre>
  
  <p>I'd like to sort the main map using values within the child map (in this case, "sequence". For example, if the map looked like this originally (the keys are the same as the groupID):  </p>
  
  <pre><code>(
      [1] =&gt; 
          (
              [groupID] =&gt; 1
              [sequence] =&gt; 0
              [command] =&gt; DefaultState
          )
  
      [2] =&gt; 
          (
              [groupID] =&gt; 2
              [sequence] =&gt; 2
              [command] =&gt; Restart
          )
  
      [3] =&gt;
          (
              [groupID] =&gt; 3
              [sequence] =&gt; 1
              [command] =&gt; Beep
          )
  
  )
  </code></pre>
  
  <p>I would want the result after using this comparator to look like this:</p>
  
  <pre><code>(
      [1] =&gt; 
          (
              [groupID] =&gt; 1
              [sequence] =&gt; 0
              [command] =&gt; DefaultState
          )
  
      [3] =&gt;
          (
              [groupID] =&gt; 3
              [sequence] =&gt; 1
              [command] =&gt; Beep
          )
  
      [2] =&gt; 
          (
              [groupID] =&gt; 2
              [sequence] =&gt; 2
              [command] =&gt; Restart
          )
  
  )
  </code></pre>
  
  <p>I had asked a similar question but not directed at using a comparator function when defining the map. The solution to my other question involved using the Boost library and tables. I'd like to keep this fairly simple and use my definition above.</p>
  
  <p>Different options would be to use the sequence value as the key for the parent map, which can be done but I'd like to use that as the last option. Is the order of a map not changeable? I'm new to this type of thinking for C++ as I'm quite new, and it's hard coming from newer languages where something like this is a bit easier.</p>
  
  <p>Thanks in advance.</p>