mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 04:19:43 +00:00
Allow Optionals to be compared to None
This is something like nullopt in std::experimental::optional. Optional could already be constructed from None, so this seems like an obvious extension from there. I have a use in a future patch for Clang, though it may not go that way/end up used - so this seemed worth committing now regardless. llvm-svn: 245518
This commit is contained in:
parent
b73f8e83f8
commit
bdabca9432
@ -159,6 +159,25 @@ template <typename T> struct isPodLike<Optional<T> > {
|
|||||||
template<typename T, typename U>
|
template<typename T, typename U>
|
||||||
void operator==(const Optional<T> &X, const Optional<U> &Y);
|
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
|
/// \brief Poison comparison between two \c Optional objects. Clients needs to
|
||||||
/// explicitly compare the underlying values and account for empty \c Optional
|
/// explicitly compare the underlying values and account for empty \c Optional
|
||||||
/// objects.
|
/// objects.
|
||||||
|
@ -377,5 +377,18 @@ TEST_F(OptionalTest, MoveGetValueOr) {
|
|||||||
|
|
||||||
#endif // LLVM_HAS_RVALUE_REFERENCE_THIS
|
#endif // LLVM_HAS_RVALUE_REFERENCE_THIS
|
||||||
|
|
||||||
|
TEST_F(OptionalTest, NoneComparison) {
|
||||||
|
Optional<int> o;
|
||||||
|
EXPECT_EQ(o, None);
|
||||||
|
EXPECT_EQ(None, o);
|
||||||
|
EXPECT_FALSE(o != None);
|
||||||
|
EXPECT_FALSE(None != o);
|
||||||
|
o = 3;
|
||||||
|
EXPECT_FALSE(o == None);
|
||||||
|
EXPECT_FALSE(None == o);
|
||||||
|
EXPECT_TRUE(o != None);
|
||||||
|
EXPECT_TRUE(None != o);
|
||||||
|
}
|
||||||
|
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user