diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2020-09-08 13:55:10 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2020-09-08 13:55:18 (GMT) |
commit | 1d74a64f3839edc6f6c5c651f8d446a7d5875fc0 (patch) | |
tree | b565434960678a20d1245c2defa7cbf26fd9f56f /Utilities | |
parent | 56134c1708bb227ebded52e66963b58acae7a958 (diff) | |
parent | 7e1304c6e61a25aac6fcf1bee47a719ac39075e5 (diff) | |
download | CMake-1d74a64f3839edc6f6c5c651f8d446a7d5875fc0.zip CMake-1d74a64f3839edc6f6c5c651f8d446a7d5875fc0.tar.gz CMake-1d74a64f3839edc6f6c5c651f8d446a7d5875fc0.tar.bz2 |
Merge topic 'cm-optional-comparison'
7e1304c6e6 cm::optional: Add comparison operators
c854e9eba5 Refactor: Add ASSERT_TRUE() macro to testOptional.cxx
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5195
Diffstat (limited to 'Utilities')
-rw-r--r-- | Utilities/std/cm/optional | 204 |
1 files changed, 204 insertions, 0 deletions
diff --git a/Utilities/std/cm/optional b/Utilities/std/cm/optional index e691e8e..9a5d840 100644 --- a/Utilities/std/cm/optional +++ b/Utilities/std/cm/optional @@ -218,6 +218,210 @@ optional<T>& optional<T>::operator=(U&& v) return *this; } +template <typename T, typename U> +bool operator==(const optional<T>& lhs, const optional<U>& rhs) +{ + if (lhs.has_value()) { + return rhs.has_value() && *lhs == *rhs; + } + return !rhs.has_value(); +} + +template <typename T, typename U> +bool operator!=(const optional<T>& lhs, const optional<U>& rhs) +{ + if (lhs.has_value()) { + return !rhs.has_value() || *lhs != *rhs; + } + return rhs.has_value(); +} + +template <typename T, typename U> +bool operator<(const optional<T>& lhs, const optional<U>& rhs) +{ + if (rhs.has_value()) { + return !lhs.has_value() || *lhs < *rhs; + } + return false; +} + +template <typename T, typename U> +bool operator<=(const optional<T>& lhs, const optional<U>& rhs) +{ + if (!lhs.has_value()) { + return true; + } + if (rhs.has_value()) { + return *lhs <= *rhs; + } + return false; +} + +template <typename T, typename U> +bool operator>(const optional<T>& lhs, const optional<U>& rhs) +{ + if (lhs.has_value()) { + return !rhs.has_value() || *lhs > *rhs; + } + return false; +} + +template <typename T, typename U> +bool operator>=(const optional<T>& lhs, const optional<U>& rhs) +{ + if (!rhs.has_value()) { + return true; + } + if (lhs.has_value()) { + return *lhs >= *rhs; + } + return false; +} + +template <typename T> +bool operator==(const optional<T>& opt, nullopt_t) noexcept +{ + return !opt.has_value(); +} + +template <typename T> +bool operator!=(const optional<T>& opt, nullopt_t) noexcept +{ + return opt.has_value(); +} + +template <typename T> +bool operator<(const optional<T>& opt, nullopt_t) noexcept +{ + return false; +} + +template <typename T> +bool operator<=(const optional<T>& opt, nullopt_t) noexcept +{ + return !opt.has_value(); +} + +template <typename T> +bool operator>(const optional<T>& opt, nullopt_t) noexcept +{ + return opt.has_value(); +} + +template <typename T> +bool operator>=(const optional<T>& opt, nullopt_t) noexcept +{ + return true; +} + +template <typename T> +bool operator==(nullopt_t, const optional<T>& opt) noexcept +{ + return !opt.has_value(); +} + +template <typename T> +bool operator!=(nullopt_t, const optional<T>& opt) noexcept +{ + return opt.has_value(); +} + +template <typename T> +bool operator<(nullopt_t, const optional<T>& opt) noexcept +{ + return opt.has_value(); +} + +template <typename T> +bool operator<=(nullopt_t, const optional<T>& opt) noexcept +{ + return true; +} + +template <typename T> +bool operator>(nullopt_t, const optional<T>& opt) noexcept +{ + return false; +} + +template <typename T> +bool operator>=(nullopt_t, const optional<T>& opt) noexcept +{ + return !opt.has_value(); +} + +template <typename T, typename U> +bool operator==(const optional<T>& opt, const U& value) +{ + return opt.has_value() && *opt == value; +} + +template <typename T, typename U> +bool operator!=(const optional<T>& opt, const U& value) +{ + return !opt.has_value() || *opt != value; +} + +template <typename T, typename U> +bool operator<(const optional<T>& opt, const U& value) +{ + return !opt.has_value() || *opt < value; +} + +template <typename T, typename U> +bool operator<=(const optional<T>& opt, const U& value) +{ + return !opt.has_value() || *opt <= value; +} + +template <typename T, typename U> +bool operator>(const optional<T>& opt, const U& value) +{ + return opt.has_value() && *opt > value; +} + +template <typename T, typename U> +bool operator>=(const optional<T>& opt, const U& value) +{ + return opt.has_value() && *opt >= value; +} + +template <typename T, typename U> +bool operator==(const T& value, const optional<U>& opt) +{ + return opt.has_value() && value == *opt; +} + +template <typename T, typename U> +bool operator!=(const T& value, const optional<U>& opt) +{ + return !opt.has_value() || value != *opt; +} + +template <typename T, typename U> +bool operator<(const T& value, const optional<U>& opt) +{ + return opt.has_value() && value < *opt; +} + +template <typename T, typename U> +bool operator<=(const T& value, const optional<U>& opt) +{ + return opt.has_value() && value <= *opt; +} + +template <typename T, typename U> +bool operator>(const T& value, const optional<U>& opt) +{ + return !opt.has_value() || value > *opt; +} + +template <typename T, typename U> +bool operator>=(const T& value, const optional<U>& opt) +{ + return !opt.has_value() || value >= *opt; +} + template <typename T> const T* optional<T>::operator->() const { |