diff options
Diffstat (limited to 'bpkg/utility')
-rw-r--r-- | bpkg/utility | 45 |
1 files changed, 4 insertions, 41 deletions
diff --git a/bpkg/utility b/bpkg/utility index b7dbf36..950a36a 100644 --- a/bpkg/utility +++ b/bpkg/utility @@ -11,7 +11,7 @@ #include <cassert> // assert() #include <iterator> // make_move_iterator() -#include <butl/utility> // casecmp(), reverse_iterate() +#include <butl/utility> // casecmp(), reverse_iterate(), etc #include <exception> // uncaught_exception() @@ -35,6 +35,9 @@ namespace bpkg using butl::casecmp; using butl::reverse_iterate; + using butl::exception_guard; + using butl::make_exception_guard; + // Widely-used paths. // extern const dir_path bpkg_dir; // .bpkg/ @@ -112,46 +115,6 @@ namespace bpkg bool quiet = false, const strings& pvars = strings (), const strings& cvars = strings ()); - - // Call a function if there is an exception. - // - - // True means we are in the body of a destructor that is being - // called as part of the exception stack unwindining. Used to - // compensate for the deficiencies of uncaught_exception() until - // C++17 uncaught_exceptions() becomes available. - // - // @@ MT: will have to be TLS. - // - extern bool exception_unwinding_dtor; - - template <typename F> - struct exception_guard; - - template <typename F> - inline exception_guard<F> - make_exception_guard (F f) - { - return exception_guard<F> (std::move (f)); - } - - template <typename F> - struct exception_guard - { - exception_guard (F f): f_ (std::move (f)) {} - ~exception_guard () - { - if (std::uncaught_exception ()) - { - exception_unwinding_dtor = true; - f_ (); - exception_unwinding_dtor = false; - } - } - - private: - F f_; - }; } #endif // BPKG_UTILITY |