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

Unified Diff: mojo/public/cpp/bindings/tests/rect_blink.h

Issue 2339413004: Allow Mojo structs as map keys (Closed)
Patch Set: Fix hash unit test on Windows Created 4 years, 3 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 | « mojo/public/cpp/bindings/tests/map_unittest.cc ('k') | mojo/public/cpp/bindings/tests/rect_blink.typemap » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/tests/rect_blink.h
diff --git a/mojo/public/cpp/bindings/tests/rect_blink.h b/mojo/public/cpp/bindings/tests/rect_blink.h
index de7a7922a589d3ee2eb21aed0b557e75170b7f74..73359895934bdc88d5c8ddd8a2322bb08d8e8fe7 100644
--- a/mojo/public/cpp/bindings/tests/rect_blink.h
+++ b/mojo/public/cpp/bindings/tests/rect_blink.h
@@ -51,6 +51,12 @@ class RectBlink {
int computeArea() const { return width_ * height_; }
+ bool operator==(const RectBlink& other) const {
+ return (x() == other.x() && y() == other.y() && width() == other.width() &&
+ height() == other.height());
+ }
+ bool operator!=(const RectBlink& other) const { return !(*this == other); }
+
private:
int x_ = 0;
int y_ = 0;
@@ -61,4 +67,17 @@ class RectBlink {
} // namespace test
} // namespace mojo
+namespace std {
+
+template <>
+struct hash<mojo::test::RectBlink> {
+ size_t operator()(const mojo::test::RectBlink& value) {
+ // Terrible hash function:
+ return (std::hash<int>()(value.x()) ^ std::hash<int>()(value.y()) ^
+ std::hash<int>()(value.width()) ^ std::hash<int>()(value.height()));
+ }
+};
+
+} // namespace std
+
#endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_BLINK_H_
« no previous file with comments | « mojo/public/cpp/bindings/tests/map_unittest.cc ('k') | mojo/public/cpp/bindings/tests/rect_blink.typemap » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698