AutoTrace
1 class AutoTrace { 2 public: 3 typedef std::function<void()> AutoTraceFun; 4 AutoTrace(AutoTraceFun beginFun, AutoTraceFun endFun) : endFun_(endFun){ 5 if (beginFun) { 6 beginFun(); 7 } 8 } 9 ~AutoTrace() { 10 if (endFun_) { 11 endFun_(); 12 } 13 } 14 15 private: 16 AutoTraceFun endFun_; 17 }; 18 19 #define AUTO_TRACE_(beginFun, endFun, l) AutoTrace autoTrace_## l (beginFun, endFun); 20 #define AUTO_TRACE(beginFun, endFun, l) AUTO_TRACE_(beginFun, endFun, l) 21 #define AUTO_TRACE_TEMP_MEMBER(beginFun, endFun) AUTO_TRACE(beginFun, endFun, __LINE__)