fork download
  1. #include <iostream>
  2.  
  3. int AOpen(const char*) { std::cout << "Aopen" << std::endl; return 0; }
  4. void AClose(int) { std::cout << "Aclose" << std::endl; }
  5.  
  6. int BOpen(const char*) { std::cout << "Bopen" << std::endl; return 0; }
  7. void BClose(int) { std::cout << "Bclose" << std::endl; }
  8.  
  9.  
  10.  
  11. template <typename H, H Open(const char*), void Close(H)>
  12. class Wrapper
  13. {
  14. public:
  15. Wrapper(const char* file) : h(Open(file)) {}
  16. ~Wrapper() { Close(h); }
  17.  
  18. Wrapper(const Wrapper&) = delete;
  19. Wrapper& operator = (const Wrapper&) = delete;
  20. private:
  21. H h;
  22. };
  23.  
  24. int main()
  25. {
  26. Wrapper<int, AOpen, AClose> wA("test");
  27. Wrapper<int, BOpen, BClose> wB("test");
  28. }
  29.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
Aopen
Bopen
Bclose
Aclose