title: How can I declare a custom sort function on std::map declaration?
body: <p>The container <code>std::map</code> always sorts keys based on their value. Is it possible to make it sort, for example, on the number of bits set upon declaration?</p>
  
  <p>I have a function for counting set bits:</p>
  
  <pre><code>for(size_t i = 0; i &lt; CHAR_BIT * sizeof value; ++i, value &gt;&gt;= 1) {
    if ((value &amp; 1) == byteState) ++num_bits;
  }
  </code></pre>
  
  <p>But I do not know how to apply it when declaring the map:</p>
  
  <pre><code>std::map&lt;int, int&gt; myMap = {
    {1,2},
    {3,4},
    //...
  }
  </code></pre>
  
  <p>I've tried to put it as a third parameter in the declaration <code>&lt;int,int,decltype(countSetBits)&gt;</code>, but with no luck.</p>