fork download
  1. #include <map>
  2. #include <set>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int row = 0;
  10. int col = 0;
  11. std::map<int, set<int>> sparseBlue;
  12.  
  13. // insert empty item
  14. auto iter = sparseBlue.insert(std::make_pair(row, std::set<int>()));
  15.  
  16. // did a new item get inserted?
  17. cout << "The item did " << (iter.second?"":"not") << " get inserted\n";
  18.  
  19.  
  20. // add item to set
  21. (*iter.first). // the map iterator
  22. second. // the set
  23. insert(col); // what we want to do
  24.  
  25. // test
  26. cout << sparseBlue[row].size() << " item(s) in the set";
  27. }
  28.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
The item did  get inserted
1 item(s) in the set