1234567891011121314151617181920
template<typename CB> class CountCalls { private: CB callback; long calls = 0; public: CountCalls(CB cb) : callback(cb) {} template<typename ...Args> decltype(auto) operator()(Args&&...args) { ++calls; return callback(std::forward<Args>(args)...); } long count() const { return calls; } };