fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4.  
  5. void SomeFunc()
  6. {
  7. auto r1_cleanup = [](int* ptr){
  8. std::cout << "r1_cleanup is called" << std::endl;
  9. };
  10.  
  11. auto r2_cleanup = [](int* ptr){
  12. std::cout << "r2_cleanup is called" << std::endl;
  13. };
  14.  
  15. auto r3_cleanup = [](int* ptr){
  16. std::cout << "r3_cleanup is called" << std::endl;
  17. };
  18.  
  19. auto lv = std::unique_ptr<int, decltype(r1_cleanup)>(new int()/*::init1(...)*/, r1_cleanup);
  20. auto cv1 = std::unique_ptr<int, decltype(r2_cleanup)>(new int()/*::init2(...)*/, r2_cleanup);
  21. auto cv2 = std::unique_ptr<int, decltype(r3_cleanup)>(new int()/*::init3(...)*/, r3_cleanup);
  22.  
  23. /*...*/
  24. }
  25.  
  26. int main() {
  27. SomeFunc();
  28. return 0;
  29. }
Success #stdin #stdout 0s 4508KB
stdin
Standard input is empty
stdout
r3_cleanup is called
r2_cleanup is called
r1_cleanup is called