[PATCH 1/2] optional: add operator== and operator!=
Matthias Maennich
maennich@google.com
Tue Mar 15 11:02:45 GMT 2022
On Mon, Mar 14, 2022 at 06:13:11PM +0000, Giuliano Procida wrote:
> * include/abg-cxx-compat.h (optional): Add operator== and
> operator!=.
>
>Signed-off-by: Giuliano Procida <gprocida@google.com>
>---
> include/abg-cxx-compat.h | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
>diff --git a/include/abg-cxx-compat.h b/include/abg-cxx-compat.h
>index 443905c7..a2cf9095 100644
>--- a/include/abg-cxx-compat.h
>+++ b/include/abg-cxx-compat.h
>@@ -91,6 +91,22 @@ public:
> }
>
> explicit operator bool() const { return has_value_; }
std signature is (at least make it noexcept):
> constexpr explicit operator bool() const noexcept;
>+
>+ bool
>+ operator==(const optional<T>& other) const
>+ {
>+ if (!has_value_ && !other.has_value_)
>+ return true;
>+ if (!has_value_ || !other.has_value_)
>+ return false;
>+ return value_ == other.value_;
>+ }
>+
>+ bool
>+ operator!=(const optional<T>& other) const
>+ {
>+ return !operator==(other);
>+ }
I believe C++17 defines those as non-member functions. Should we follow
that for compatibility. Eventually, when switching to C++17 or later we
would want to just replace abg_compat:: with std:: and things should
"just work".
Cheers,
Matthias
> };
>
> #endif
>--
>2.35.1.723.g4982287a31-goog
>
More information about the Libabigail
mailing list