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


##########
src/butil/memory/scope_guard.h:
##########
@@ -83,6 +84,31 @@ ScopeGuard<Callback> MakeScopeGuard(Callback&& callback) 
noexcept {
     return ScopeGuard<Callback>{ std::forward<Callback>(callback)};
 }
 
+namespace internal {
+// for BAIDU_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(prefix, __COUNTER__)
+
+// The code in the braces of BAIDU_SCOPE_EXIT always executes at the end of 
the scope.
+// Variables used within BAIDU_SCOPE_EXIT are captured by reference.
+// Example:
+// int fd = open(...);
+// BAIDU_SCOPE_EXIT {
+//     close(fd);
+// };
+// use fd ...
+//
+#define BAIDU_SCOPE_EXIT                                     \

Review Comment:
   嗯,改成BRPC更合适。



##########
src/butil/memory/scope_guard.h:
##########
@@ -83,6 +84,31 @@ ScopeGuard<Callback> MakeScopeGuard(Callback&& callback) 
noexcept {
     return ScopeGuard<Callback>{ std::forward<Callback>(callback)};
 }
 
+namespace internal {
+// for BAIDU_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(prefix, __COUNTER__)
+
+// The code in the braces of BAIDU_SCOPE_EXIT always executes at the end of 
the scope.
+// Variables used within BAIDU_SCOPE_EXIT are captured by reference.
+// Example:
+// int fd = open(...);
+// BAIDU_SCOPE_EXIT {
+//     close(fd);
+// };
+// use fd ...
+//
+#define BAIDU_SCOPE_EXIT                                     \

Review Comment:
   done



-- 
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