on_block_exit.h 317 B

12345678910111213141516171819
  1. #pragma once
  2. #include <functional>
  3. namespace jvalidate::detail {
  4. class OnBlockExit {
  5. private:
  6. std::function<void()> callback_;
  7. public:
  8. OnBlockExit() = default;
  9. template <typename F> OnBlockExit(F && callback) : callback_(callback) {}
  10. ~OnBlockExit() {
  11. if (callback_) {
  12. callback_();
  13. }
  14. }
  15. };
  16. }