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_