fork(2) download
  1. #include <map>
  2. #include <bitset>
  3. #include <iostream>
  4.  
  5. int main() {
  6. auto comp = [](int a, int b) { return std::bitset<32>(a).count() < std::bitset<32>(b).count(); };
  7. std::map<int, int, decltype(comp)> m {{{13, 1}, {15, 1}, {17, 1}}, comp};
  8.  
  9. for (auto const &p : m)
  10. std::cout << p.first << " (" << std::bitset<32>(p.first).count() << " bits)"<< std::endl;
  11.  
  12. return 0;
  13. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
17 (2 bits)
13 (3 bits)
15 (4 bits)