From fc85ca4d2e54d79ff3d319c0480f7f10265b0024 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Mon, 18 Mar 2024 16:57:29 +0800 Subject: [PATCH] feat remove defer --- src/ulib/utils/defer.h | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/ulib/utils/defer.h b/src/ulib/utils/defer.h index 5e280b9..3771e5a 100644 --- a/src/ulib/utils/defer.h +++ b/src/ulib/utils/defer.h @@ -18,20 +18,17 @@ public: Defer(DeferFunc &&defer_func) { Add(std::move(defer_func)); } - Defer(Defer &&other) noexcept : defer_funcs_(std::move(other.defer_funcs_)) - {} + Defer(Defer &&other) noexcept : defer_funcs_(std::move(other.defer_funcs_)) {} ~Defer() { - std::for_each(defer_funcs_.rbegin(), defer_funcs_.rend(), - [](const DeferFunc &defer_func) { defer_func(); }); + std::for_each(defer_funcs_.rbegin(), defer_funcs_.rend(), [](const DeferFunc &defer_func) { defer_func(); }); } template void Add(F &&func, Args &&...args) { - defer_funcs_.push_back( - std::bind(std::forward(func), std::forward(args)...)); + defer_funcs_.push_back(std::bind(std::forward(func), std::forward(args)...)); } void Clear() { defer_funcs_.clear(); } @@ -40,12 +37,12 @@ private: std::vector defer_funcs_; }; -#define _ULIB_DEFER_CONCAT(a, b) a##b -#define ULIB_DEFER_CONCAT(a, b) _ULIB_DEFER_CONCAT(a, b) +// #define _ULIB_DEFER_CONCAT(a, b) a##b +// #define ULIB_DEFER_CONCAT(a, b) _ULIB_DEFER_CONCAT(a, b) -#define defer(x) \ - ::ulib::Defer ULIB_DEFER_CONCAT(__ulib_defer__, __LINE__) = \ - ::ulib::Defer(x); +// #define defer(x) \ +// ::ulib::Defer ULIB_DEFER_CONCAT(__ulib_defer__, __LINE__) = \ +// ::ulib::Defer(x); }// namespace ulib #endif// ULIB_SRC_ULIB_UTILS_DEFER_H_