From 7153cb8a0bd6a0d405e2d84975812164233be4f6 Mon Sep 17 00:00:00 2001 From: DS Date: Fri, 21 Oct 2022 17:11:41 +0200 Subject: Fix formspec focus (#12795) --- src/util/Optional.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/util') diff --git a/src/util/Optional.h b/src/util/Optional.h index eda7fff89..c060efeb5 100644 --- a/src/util/Optional.h +++ b/src/util/Optional.h @@ -103,3 +103,57 @@ public: explicit operator bool() const { return m_has_value; } }; + +template +constexpr bool operator==(const Optional &opt, nullopt_t) +{ + return !opt.has_value(); +} +template +constexpr bool operator==(nullopt_t, const Optional &opt) +{ + return !opt.has_value(); +} +template +constexpr bool operator!=(const Optional &opt, nullopt_t) +{ + return opt.has_value(); +} +template +constexpr bool operator!=(nullopt_t, const Optional &opt) +{ + return opt.has_value(); +} + +template +constexpr bool operator==(const Optional &opt, const U &value) +{ + return opt.has_value() && *opt == value; +} +template +constexpr bool operator==(const T &value, const Optional &opt) +{ + return opt.has_value() && value == *opt; +} +template +constexpr bool operator!=(const Optional &opt, const U &value) +{ + return !opt.has_value() || *opt != value; +} +template +constexpr bool operator!=(const T &value, const Optional &opt) +{ + return !opt.has_value() || value != *opt; +} + + +template +constexpr bool operator==(const Optional &lhs, const Optional &rhs) +{ + return lhs.has_value() ? *lhs == rhs : nullopt == rhs; +} +template +constexpr bool operator!=(const Optional &lhs, const Optional &rhs) +{ + return lhs.has_value() ? *lhs != rhs : nullopt != rhs; +} -- cgit v1.2.3