diff --git a/include/ircd/util.h b/include/ircd/util.h index 0f9a44b7b..3d0f15f5c 100644 --- a/include/ircd/util.h +++ b/include/ircd/util.h @@ -63,45 +63,62 @@ struct NAME \ IRCD_STRONG_TYPEDEF(TYPE, IRCD_UNIQUE(strong_t)) -template -using custom_ptr = std::unique_ptr>; - - struct scope { - struct uncaught; + struct nominal; + struct exceptional; const std::function func; template - scope(F &&func) - :func(std::forward(func)) - {} - + scope(F &&func): func(std::forward(func)) {} + scope() = default; scope(const scope &) = delete; + scope &operator=(const scope &) = delete; ~scope() noexcept { func(); } }; -struct scope::uncaught +struct scope::nominal +:scope { - const std::function func; - template - uncaught(F &&func) - :func(std::forward(func)) - {} - - uncaught(const uncaught &) = delete; - ~uncaught() noexcept + nominal(F &&func) + :scope { - if(unlikely(std::uncaught_exception())) - func(); - } + [func(std::forward(func))] + { + if(likely(!std::uncaught_exception())) + func(); + } + }{} + + nominal() = default; }; +struct scope::exceptional +:scope +{ + template + exceptional(F &&func) + :scope + { + [func(std::forward(func))] + { + if(unlikely(std::uncaught_exception())) + func(); + } + }{} + + exceptional() = default; +}; + + +template +using custom_ptr = std::unique_ptr>; + // For conforming enums include a _NUM_ as the last element, // then num_of() works