Advertisement
obernardovieira

Delete unordered_map registry when looping

Nov 21st, 2013
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <unordered_map>
  2. #include <iostream>
  3.  
  4. int total = 1;
  5.  
  6. typedef std::unordered_map<char, bool> mapa;
  7. typedef std::unordered_map<int, mapa> stu_mapa;
  8. stu_mapa STU_mapa;
  9.  
  10. void add(char letter, bool verdade) {
  11.     std::unordered_map<char, bool> ma_pa;
  12.     ma_pa[letter] = verdade;
  13.     STU_mapa.insert(stu_mapa::value_type(total, ma_pa));
  14.     total ++;
  15.     return;
  16. }
  17.  
  18. int main() {
  19.     std::cout << "Inicio" << std::endl;
  20.     add('a',false);
  21.     add('b',false);
  22.     add('c',false);
  23.     add('d',true);
  24.     add('e',true);
  25.     add('f',false);
  26.  
  27.     for(stu_mapa::reverse_iterator j = STU_mapa.rbegin(); j!=STU_mapa.rend(); j++) {
  28.         std::unordered_map<char, bool> ma_pa = j->second;
  29.         std::unordered_map<char, bool>::const_iterator k = ma_pa.begin();
  30.         if(k->second == true) {
  31.             std::cout << "delete " << j->first << std::endl;
  32.             STU_mapa.erase(j->first);
  33.             j--;
  34.         }
  35.         else {
  36.             std::cout << j->first << std::endl;
  37.         }
  38.     }
  39.  
  40.     std::cout << "desce" << std::endl << std::endl;
  41.  
  42.     for(stu_mapa::reverse_iterator j = STU_mapa.rbegin(); j!=STU_mapa.rend(); j++) {
  43.         std::cout << j->first << std::endl;
  44.     }
  45.  
  46.     system("pause");
  47.     return 1;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement