diff options
| author | DS <vorunbekannt75@web.de> | 2022-10-21 17:11:41 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-21 17:11:41 +0200 |
| commit | 7153cb8a0bd6a0d405e2d84975812164233be4f6 (patch) | |
| tree | ed9aca93153bdd84392be670674bb96d19f98cf5 /src/util | |
| parent | 9f0d88407d9dadb1a8cf8c03131eda034f2f19e1 (diff) | |
| download | minetest-7153cb8a0bd6a0d405e2d84975812164233be4f6.tar.xz | |
Fix formspec focus (#12795)
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/Optional.h | 54 |
1 files changed, 54 insertions, 0 deletions
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 <typename T> +constexpr bool operator==(const Optional<T> &opt, nullopt_t) +{ + return !opt.has_value(); +} +template <typename T> +constexpr bool operator==(nullopt_t, const Optional<T> &opt) +{ + return !opt.has_value(); +} +template <typename T> +constexpr bool operator!=(const Optional<T> &opt, nullopt_t) +{ + return opt.has_value(); +} +template <typename T> +constexpr bool operator!=(nullopt_t, const Optional<T> &opt) +{ + return opt.has_value(); +} + +template <typename T, typename U> +constexpr bool operator==(const Optional<T> &opt, const U &value) +{ + return opt.has_value() && *opt == value; +} +template <typename T, typename U> +constexpr bool operator==(const T &value, const Optional<U> &opt) +{ + return opt.has_value() && value == *opt; +} +template <typename T, typename U> +constexpr bool operator!=(const Optional<T> &opt, const U &value) +{ + return !opt.has_value() || *opt != value; +} +template <typename T, typename U> +constexpr bool operator!=(const T &value, const Optional<U> &opt) +{ + return !opt.has_value() || value != *opt; +} + + +template <typename T, typename U> +constexpr bool operator==(const Optional<T> &lhs, const Optional<U> &rhs) +{ + return lhs.has_value() ? *lhs == rhs : nullopt == rhs; +} +template <typename T, typename U> +constexpr bool operator!=(const Optional<T> &lhs, const Optional<U> &rhs) +{ + return lhs.has_value() ? *lhs != rhs : nullopt != rhs; +} |
