fork download
  1. #include <iostream>
  2. #include <memory>
  3. #include <unordered_map>
  4.  
  5. class Test
  6. {
  7. public:
  8. Test(){}
  9. ~Test(){}
  10.  
  11. int test;
  12. };
  13.  
  14. typedef std::shared_ptr<Test> Test_ptr;
  15. typedef std::unordered_map<std::string, Test_ptr> TestMap;
  16.  
  17. int main()
  18. {
  19. TestMap map1, map2;
  20. std::string key("abc");
  21. Test_ptr ptr(new Test);
  22. map1.insert(TestMap::value_type(key, ptr));
  23.  
  24. TestMap::iterator iter = map1.find(key);
  25. if (iter != map1.end())
  26. {
  27. map2.insert(*iter);
  28. if (iter->second == nullptr)
  29. {
  30. std::cout << "after insert the shared ptr becomes null" << std::endl;
  31. }
  32. }
  33. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
Standard output is empty