summaryrefslogtreecommitdiffstats
path: root/Utilities
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2020-08-29 18:05:53 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2020-09-07 12:50:09 (GMT)
commit7e1304c6e61a25aac6fcf1bee47a719ac39075e5 (patch)
tree695135b12da603c1a971f2f09d73786c794b8c90 /Utilities
parentc854e9eba57841fdbcb2258adbfabee9df7bab03 (diff)
downloadCMake-7e1304c6e61a25aac6fcf1bee47a719ac39075e5.zip
CMake-7e1304c6e61a25aac6fcf1bee47a719ac39075e5.tar.gz
CMake-7e1304c6e61a25aac6fcf1bee47a719ac39075e5.tar.bz2
cm::optional: Add comparison operators
Diffstat (limited to 'Utilities')
-rw-r--r--Utilities/std/cm/optional204
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
{