#pragma once #include namespace jvalidate::detail { class OnBlockExit { private: std::function callback_; public: OnBlockExit() = default; template OnBlockExit(F && callback) : callback_(callback) {} OnBlockExit(OnBlockExit && other) { std::swap(other.callback_, callback_); } OnBlockExit & operator=(OnBlockExit && other) { std::swap(other.callback_, callback_); return *this; } ~OnBlockExit() { if (callback_) { callback_(); } } }; }