yanglimingcn commented on code in PR #2643:
URL: https://github.com/apache/brpc/pull/2643#discussion_r1598329826


##########
src/butil/memory/scope_guard.h:
##########
@@ -83,6 +84,25 @@ ScopeGuard<Callback> MakeScopeGuard(Callback&& callback) 
noexcept {
     return ScopeGuard<Callback>{ std::forward<Callback>(callback)};
 }
 
-}
+namespace internal {
+// for SCOPE_EXIT.
+enum class ScopeExitHelper {};
+
+template<typename Callback>
+ScopeGuard<Callback>
+operator+(ScopeExitHelper, Callback&& callback) {
+    return MakeScopeGuard(std::forward<Callback>(callback));
+} // namespace internal
+} // namespace butil
+
+#define BAIDU_ANONYMOUS_VARIABLE(prefix) BAIDU_CONCAT(ptrfix, __COUNTER__)
+
+// The code in the braces of SCOPE_EXIT always executes at the end of the 
scope.
+// Variables used within SCOPE_EXIT are captured by reference.
+#define SCOPE_EXIT                                           \

Review Comment:
   带上一个参数,允许用户自定义lambda表达式是不是更灵活,类似golang的defer



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to