fork(1) download
  1. #include<iostream>
  2. #include <unordered_map>
  3.  
  4. using namespace std;
  5. int main(int argc, char** argv) {
  6. unordered_map<int, int> map1{
  7. {1, -10},
  8. {10, -1},
  9. {2, 5},
  10. };
  11. decltype(map1) map2;
  12.  
  13. for(auto &elem: map1) {
  14. if(elem.second < 0) {
  15. map2.emplace(elem.first, elem.second);
  16. map1.erase(elem.first);
  17. }
  18. }
  19.  
  20. for(auto &elem: map2) {
  21. cout << "negative value pair = " << elem.first << ", " << elem.second << endl;
  22. }
  23. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
negative value pair = 1, -10