Commit a5ed9ec0 authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

Mojo: Add operator== for struct/union classes

We generate Equals() methods for struct and union wrapper classes.
There's not really a good reason to do this instead of operator==, and
operator== plays nicely with gmock matchers.

This adds operator== to do the same thing as Equals.

Bug: 735302
Change-Id: I4ab8c70aa4ba0276aec7a2f64734c710a090d6f3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2456148
Commit-Queue: Ken Rockot <rockot@google.com>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815303}
parent acac1860
...@@ -59,6 +59,9 @@ class {{export_attribute}} {{struct.name}} { ...@@ -59,6 +59,9 @@ class {{export_attribute}} {{struct.name}} {
template <typename T, {{struct.name}}::EnableIfSame<T>* = nullptr> template <typename T, {{struct.name}}::EnableIfSame<T>* = nullptr>
bool Equals(const T& other) const; bool Equals(const T& other) const;
template <typename T, {{struct.name}}::EnableIfSame<T>* = nullptr>
bool operator==(const T& rhs) const { return Equals(rhs); }
{%- if struct|is_hashable %} {%- if struct|is_hashable %}
size_t Hash(size_t seed) const; size_t Hash(size_t seed) const;
{%- endif %} {%- endif %}
......
...@@ -49,6 +49,11 @@ class {{export_attribute}} {{union.name}} { ...@@ -49,6 +49,11 @@ class {{export_attribute}} {{union.name}} {
T, {{union.name}}>::value>::type* = nullptr> T, {{union.name}}>::value>::type* = nullptr>
bool Equals(const T& other) const; bool Equals(const T& other) const;
template <typename T,
typename std::enable_if<std::is_same<
T, {{union.name}}>::value>::type* = nullptr>
bool operator==(const T& rhs) const { return Equals(rhs); }
{%- if union|is_hashable %} {%- if union|is_hashable %}
size_t Hash(size_t seed) const; size_t Hash(size_t seed) const;
{%- endif %} {%- endif %}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment