Skip to content

Commit

Permalink
comment on namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
liss-h committed Jan 30, 2024
1 parent b42fbfc commit cbcfa00
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions include/dice/template-library/defer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,12 @@ namespace dice::template_library {
return ScopeExitGuard<ScopeExitPolicy::OnSuccess, std::remove_cvref_t<F>>{std::forward<F>(func)};
}

namespace detail {
/**
* Helper types and functions whose only purpose it to improve
* the syntax of the provided `DEFER*` macros to make them seem more like actual language
* constructs rather than macros (see macro definitions below).
*/

/**
* Helper types and functions whose only purpose it to improve
* the syntax of the provided `DEFER*` macros to make them seem more like actual language
* constructs rather than macros (see macro definitions below).
*/
namespace defer_detail {
struct ScopeGuardOnExit {};
struct ScopeGuardOnFail {};
struct ScopeGuardOnSuccess {};
Expand All @@ -125,7 +124,7 @@ namespace dice::template_library {
auto operator+(ScopeGuardOnSuccess, F &&func) {
return make_scope_success_guard(std::forward<F>(func));
}
} // namespace detail
} // namespace defer_detail

} // namespace dice::template_library

Expand All @@ -148,20 +147,20 @@ namespace dice::template_library {
* @endcode
*/
#define DEFER \
auto DICE_TEMPLATE_LIBRARY_DETAIL_SCOPEGUARD_VAR = ::dice::template_library::detail::ScopeGuardOnExit{} + [&]() noexcept
auto DICE_TEMPLATE_LIBRARY_DETAIL_SCOPEGUARD_VAR = ::dice::template_library::defer_detail::ScopeGuardOnExit{} + [&]() noexcept

/**
* Similar to DEFER, but it only executes the expression if the scope failed (i.e. the scope threw an exception).
* Note the evaluated expression is not allowed to throw.
*/
#define DEFER_TO_FAIL \
auto DICE_TEMPLATE_LIBRARY_DETAIL_SCOPEGUARD_VAR = ::dice::template_library::detail::ScopeGuardOnFail{} + [&]() noexcept
auto DICE_TEMPLATE_LIBRARY_DETAIL_SCOPEGUARD_VAR = ::dice::template_library::defer_detail::ScopeGuardOnFail{} + [&]() noexcept

/**
* Similar to DEFER, but it only executes the expression if the scope succeeded (i.e. the scope did not throw an exception).
* Note the evaluated expression is allowed to throw.
*/
#define DEFER_TO_SUCCESS \
auto DICE_TEMPLATE_LIBRARY_DETAIL_SCOPEGUARD_VAR = ::dice::template_library::detail::ScopeGuardOnSuccess{} + [&]()
auto DICE_TEMPLATE_LIBRARY_DETAIL_SCOPEGUARD_VAR = ::dice::template_library::defer_detail::ScopeGuardOnSuccess{} + [&]()

#endif // DICE_TEMPLATE_LIBRARY_DEFER_HPP

0 comments on commit cbcfa00

Please sign in to comment.