This is an automated email from the ASF dual-hosted git repository.
wwbmmm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git
The following commit(s) were added to refs/heads/master by this push:
new fed62751 Support macro to disable move (#2989)
fed62751 is described below
commit fed627513ebd0c3dbadc52f981be1b70b38ebbd5
Author: Bright Chen <[email protected]>
AuthorDate: Fri Jun 13 11:56:31 2025 +0800
Support macro to disable move (#2989)
---
src/butil/macros.h | 37 +++++++++++++++++++++++++++++--------
1 file changed, 29 insertions(+), 8 deletions(-)
diff --git a/src/butil/macros.h b/src/butil/macros.h
index 6519a105..63bb64de 100644
--- a/src/butil/macros.h
+++ b/src/butil/macros.h
@@ -20,8 +20,11 @@
// There must be many copy-paste versions of these macros which are same
// things, undefine them to avoid conflict.
#undef DISALLOW_COPY
+#undef DISALLOW_MOVE
#undef DISALLOW_ASSIGN
+#undef DISALLOW_MOVE_ASSIGN
#undef DISALLOW_COPY_AND_ASSIGN
+#undef DISALLOW_COPY_AND_MOVE
#undef DISALLOW_EVIL_CONSTRUCTORS
#undef DISALLOW_IMPLICIT_CONSTRUCTORS
@@ -31,20 +34,38 @@
#define BUTIL_DELETE_FUNCTION(decl) decl = delete
#endif
-// Put this in the private: declarations for a class to be uncopyable.
+// Declarations for a class to be uncopyable.
#define DISALLOW_COPY(TypeName) \
BUTIL_DELETE_FUNCTION(TypeName(const TypeName&))
-// Put this in the private: declarations for a class to be unassignable.
-#define DISALLOW_ASSIGN(TypeName) \
- BUTIL_DELETE_FUNCTION(void operator=(const TypeName&))
+// Declarations for a class to be unmovable.
+#define DISALLOW_MOVE(TypeName) \
+ BUTIL_DELETE_FUNCTION(TypeName(TypeName&&))
-// A macro to disallow the copy constructor and operator= functions
-// This should be used in the private: declarations for a class
-#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
- BUTIL_DELETE_FUNCTION(TypeName(const TypeName&)); \
+// Declarations for a class to be unassignable.
+#define DISALLOW_ASSIGN(TypeName) \
BUTIL_DELETE_FUNCTION(void operator=(const TypeName&))
+// Declarations for a class to be move-unassignable.
+#define DISALLOW_MOVE_ASSIGN(TypeName) \
+ BUTIL_DELETE_FUNCTION(void operator=(TypeName&&))
+
+// A macro to disallow the copy constructor and operator= functions.
+#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
+ DISALLOW_COPY(TypeName); \
+ DISALLOW_ASSIGN(TypeName)
+
+// A macro to disallow the move constructor and operator= functions.
+#define DISALLOW_MOVE_AND_ASSIGN(TypeName) \
+ DISALLOW_MOVE(TypeName); \
+ DISALLOW_MOVE_ASSIGN(TypeName)
+
+// A macro to disallow the copy constructor,
+// the move constructor and operator= functions.
+#define DISALLOW_COPY_AND_MOVE(TypeName) \
+ DISALLOW_COPY_AND_ASSIGN(TypeName); \
+ DISALLOW_MOVE(TypeName)
+
// An older, deprecated, politically incorrect name for the above.
// NOTE: The usage of this macro was banned from our code base, but some
// third_party libraries are yet using it.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]