fork(1) download
  1. #include <iostream>
  2. #include <memory>
  3. #include <map>
  4.  
  5. struct method {
  6. virtual ~method() { std::cout << "f\n"; };
  7. };
  8. typedef std::unique_ptr<method> MPTR;
  9.  
  10. std::map<int, MPTR> tbl;
  11.  
  12. void insert(int id, MPTR m) {
  13. tbl.insert(std::make_pair(id, std::move(m)));
  14. };
  15.  
  16. void set(int id, MPTR m) {
  17. tbl[id] = std::move(m);
  18. };
  19.  
  20. int main()
  21. {
  22. insert(1, MPTR(new method)); // or insert(1, std:::make_unique<method>()) in C++14 and later
  23. set(1, MPTR(new method)); // or set(1, std:::make_unique<method>()) in C++14 and later
  24. return 0;
  25. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
f
f