Allow Optionals to be compared to None
[oota-llvm.git] / include / llvm / ADT / Optional.h
index 855ab890392ee26e103e36f7aee3b469c15c7176..d9acaf6d23b00d8d729db9ccbce596e436e9b647 100644 (file)
@@ -159,6 +159,25 @@ template <typename T> struct isPodLike<Optional<T> > {
 template<typename T, typename U>
 void operator==(const Optional<T> &X, const Optional<U> &Y);
 
+template<typename T>
+bool operator==(const Optional<T> &X, NoneType) {
+  return !X.hasValue();
+}
+
+template<typename T>
+bool operator==(NoneType, const Optional<T> &X) {
+  return X == None;
+}
+
+template<typename T>
+bool operator!=(const Optional<T> &X, NoneType) {
+  return !(X == None);
+}
+
+template<typename T>
+bool operator!=(NoneType, const Optional<T> &X) {
+  return X != None;
+}
 /// \brief Poison comparison between two \c Optional objects. Clients needs to
 /// explicitly compare the underlying values and account for empty \c Optional
 /// objects.