#ifndef LIPSYNC_TOOLS_H #define LIPSYNC_TOOLS_H #include #include #define UNUSED(x) ((void)(x)) template using lambda_unique_ptr = std::unique_ptr>; // The following definitions are taken from https://github.com/Microsoft/GSL. // final_act allows you to ensure something gets run at the end of a scope template class final_act { public: explicit final_act(F f) noexcept : f_(std::move(f)), invoke_(true) {} final_act(final_act&& other) noexcept : f_(std::move(other.f_)), invoke_(other.invoke_) { other.invoke_ = false; } final_act(const final_act&) = delete; final_act& operator=(const final_act&) = delete; ~final_act() noexcept { if (invoke_) f_(); } private: F f_; bool invoke_; }; // finally() - convenience function to generate a final_act template final_act finally(const F &f) noexcept { return final_act(f); } template final_act finally(F &&f) noexcept { return final_act(std::forward(f)); } #endif //LIPSYNC_TOOLS_H