-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
50 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
#ifndef MAMBA_CORE_UTIL_SCOPE_HPP | ||
#define MAMBA_CORE_UTIL_SCOPE_HPP | ||
|
||
#include <stdexcept> | ||
#include "mamba/core/output.hpp" | ||
|
||
namespace mamba | ||
{ | ||
|
||
template <typename F> | ||
struct on_scope_exit | ||
{ | ||
F func; | ||
|
||
explicit on_scope_exit(F&& f) | ||
: func(std::forward<F>(f)) | ||
{ | ||
} | ||
|
||
~on_scope_exit() | ||
{ | ||
try | ||
{ | ||
func(); | ||
} | ||
catch (const std::exception& ex) | ||
{ | ||
LOG_ERROR << fmt::format("Scope exit error (catched and ignored): {}", ex.what()); | ||
} | ||
catch (...) | ||
{ | ||
LOG_ERROR << "Scope exit unknown error (catched and ignored)"; | ||
} | ||
} | ||
|
||
// Deactivate copy & move until we implement moves | ||
on_scope_exit(const on_scope_exit&) = delete; | ||
on_scope_exit& operator=(const on_scope_exit&) = delete; | ||
on_scope_exit(on_scope_exit&&) = delete; | ||
on_scope_exit& operator=(on_scope_exit&&) = delete; | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters