fork download
  1. # include <map>
  2. # include <iostream>
  3.  
  4. struct node {
  5. int test;
  6. } temp;
  7.  
  8. int main() {
  9. temp.test = 24;
  10.  
  11. auto comp = [](const node& n1, const node& n2) { return n1.test < n2.test; };
  12. std::map<node, bool, decltype(comp)> mymap1(comp);
  13.  
  14. mymap1.insert(std::make_pair(temp, true));
  15. mymap1.emplace(node({ 48 }), true);
  16. mymap1[{ 12 }] = false;
  17.  
  18. for (auto const &n : mymap1)
  19. std::cout << n.first.test << ": " << n.second << std::endl;
  20.  
  21. /*
  22.   // C++17 allows to use range-based for loops together with structured bindings.
  23.   for (auto const &[k, v] : mymap1)
  24.   std::cout << k.test << ": " << v << std::endl;
  25.   */
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
12: 0
24: 1
48: 1