fork download
  1. #include <memory>
  2. #include <iostream>
  3.  
  4.  
  5. template< typename T, typename D>
  6. class ptrptr_type {
  7. using parent_type = std::unique_ptr<T, D>;
  8. using pointer = typename parent_type::pointer;
  9.  
  10. parent_type* p;
  11. pointer a;
  12. ptrptr_type(const ptrptr_type& nocopy) = delete;
  13. ptrptr_type& operator=(const ptrptr_type& nocopy) = delete;
  14. public:
  15. ptrptr_type (std::unique_ptr<T, D>& ptr) : p(&ptr), a(ptr.release()) {}
  16. ptrptr_type(ptrptr_type&& mover) {p = mover.p; a = mover.a; mover.p = nullptr;}
  17. ptrptr_type& operator=(ptrptr_type&& mover) {p = mover.p; a = mover.a; mover.p = nullptr; return *this;}
  18. operator pointer*() {return &a;}
  19. ~ptrptr_type () {if (p) p->reset(a);}
  20. };
  21. template< typename T, typename D>
  22. ptrptr_type<T,D> ptrptr(std::unique_ptr<T, D>& ptr) {return ptrptr_type<T, D>(ptr);}
  23.  
  24. void FuckingCOM ( int** cominitializegogo ) {delete *cominitializegogo; *cominitializegogo = new int(48);}
  25.  
  26. int main () {
  27. std::unique_ptr<int> meow( new int(24) );
  28. FuckingCOM ( ptrptr(meow) );
  29. std::cout << *meow << std::endl;
  30. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
48