Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Unified Diff: Source/wtf/Assertions.h

Issue 309083003: Add macros to define comparison operators to compare by reference or pointer interchangeably (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/rendering/RenderObject.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/Assertions.h
diff --git a/Source/wtf/Assertions.h b/Source/wtf/Assertions.h
index 73fc317c6c5c2880275b8cc3bc2aa777acae5fc9..ca91dd2bcf039897f93153a6b7e186ac617cf999 100644
--- a/Source/wtf/Assertions.h
+++ b/Source/wtf/Assertions.h
@@ -362,6 +362,24 @@ static inline void UNREACHABLE_FOR_PLATFORM()
#define RELEASE_ASSERT_NOT_REACHED() ASSERT_NOT_REACHED()
#endif
+/* DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES */
+
+// Allow equality comparisons of Objects by reference or pointer, interchangeably.
+#define DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(thisType) \
+ inline bool operator==(const thisType& a, const thisType& b) { return &a == &b; } \
+ inline bool operator==(const thisType& a, const thisType* b) { return &a == b; } \
+ inline bool operator==(const thisType* a, const thisType& b) { return a == &b; } \
+ inline bool operator!=(const thisType& a, const thisType& b) { return !(a == b); } \
+ inline bool operator!=(const thisType& a, const thisType* b) { return !(a == b); } \
+ inline bool operator!=(const thisType* a, const thisType& b) { return !(a == b); }
+
+#define DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES_REFCOUNTED(thisType) \
+ DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(thisType) \
+ inline bool operator==(const PassRefPtr<thisType>& a, const thisType& b) { return a.get() == &b; } \
+ inline bool operator==(const thisType& a, const PassRefPtr<thisType>& b) { return &a == b.get(); } \
+ inline bool operator!=(const PassRefPtr<thisType>& a, const thisType& b) { return !(a == b); } \
+ inline bool operator!=(const thisType& a, const PassRefPtr<thisType>& b) { return !(a == b); }
+
/* DEFINE_TYPE_CASTS */
#define DEFINE_TYPE_CASTS(thisType, argumentType, argumentName, pointerPredicate, referencePredicate) \
« no previous file with comments | « Source/core/rendering/RenderObject.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698