fork download
  1. #include <memory>
  2. #include <cstdio>
  3. template <class T,class R> struct call_ifn0_t {
  4. R (*f)(T);
  5. void operator()(T t) { if ( t ) f(t); }
  6. };
  7.  
  8. template <class T,class R> call_ifn0_t<T,R> call_ifn0(R(*f)(T)) {
  9. return { f };
  10. }
  11.  
  12. typedef std::shared_ptr<void> ptrdtor;
  13. #define MACRO_CONCAT1(a,b) a##b
  14. #define MACRO_CONCAT(a,b) MACRO_CONCAT1(a,b)
  15. #define UNIQNAME MACRO_CONCAT(local_uniqname_at_line_,__LINE__)
  16.  
  17. int main()
  18. {
  19. FILE *f; ptrdtor UNIQNAME( f = fopen(".","r"), call_ifn0(fclose) );
  20. printf("file: %p",f);
  21. }
  22.  
Success #stdin #stdout 0s 3020KB
stdin
Standard input is empty
stdout
file: 0x8673008