| 1234567891011121314151617181920212223242526 |
- #pragma once
- #include <functional>
- namespace jvalidate::detail {
- class OnBlockExit {
- private:
- std::function<void()> callback_;
- public:
- OnBlockExit() = default;
- template <typename F> 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_();
- }
- }
- };
- }
|