Skip to content

Commit 55657a8

Browse files
snarkmasterfacebook-github-bot
authored andcommitted
Add operator==
Reviewed By: ispeters Differential Revision: D72884582 fbshipit-source-id: d33645226c1ffbad57eee65b3552a7fca7a3d09b
1 parent 507ea35 commit 55657a8

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

third-party/folly/src/folly/ExceptionWrapper.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ class exception_wrapper final {
228228
std::exception_ptr to_exception_ptr() const noexcept;
229229
std::exception_ptr const& exception_ptr_ref() const noexcept;
230230

231+
//! \return `true` if the wrappers point to the same exception object
232+
friend inline bool operator==(
233+
exception_wrapper const& lhs, exception_wrapper const& rhs) noexcept {
234+
return lhs.ptr_ == rhs.ptr_;
235+
}
236+
231237
//! Returns the `typeid` of the wrapped exception object. If there is no
232238
//! wrapped exception object, returns `nullptr`.
233239
std::type_info const* type() const noexcept;

third-party/folly/src/folly/result/result.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ class result_crtp {
286286
return b.exp_.hasValue() && a.exp_.value() == b.exp_.value();
287287
} else if (a.exp_.hasError()) {
288288
return b.exp_.hasError() &&
289-
a.exp_.error().error().exception_ptr_ref() ==
290-
b.exp_.error().error().exception_ptr_ref();
289+
a.exp_.error().error() == b.exp_.error().error();
291290
} else { // `a` empty
292291
return b.is_expected_empty(); // equal iff both are empty
293292
}

third-party/folly/src/folly/result/test/result_test.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@ TEST(Result, copyMethod) {
202202

203203
result<int> rErr{make_exception_wrapper<MyError>("grr")};
204204
auto rErrToo = rErr.copy();
205-
EXPECT_TRUE(
206-
rErr.non_value().error().exception_ptr_ref() ==
207-
rErrToo.non_value().error().exception_ptr_ref());
205+
EXPECT_EQ(rErr.non_value().error(), rErrToo.non_value().error());
208206
EXPECT_TRUE(rErr == rErrToo);
209207

210208
EXPECT_TRUE(rErr != r);

third-party/folly/src/folly/test/ExceptionWrapperTest.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,21 @@ TEST(ExceptionWrapper, members) {
100100
EXPECT_EQ(ew.class_name(), kRuntimeErrorClassName);
101101
}
102102

103+
TEST(ExceptionWrapper, equality) {
104+
auto ew = make_exception_wrapper<std::runtime_error>("wat");
105+
EXPECT_EQ(ew, ew);
106+
107+
auto ewSame = ew;
108+
EXPECT_EQ(ew, ewSame);
109+
110+
// Before C++20, operator!= is not defaulted based on operator==
111+
#if FOLLY_CPLUSPLUS >= 202002L
112+
auto ewDiff = make_exception_wrapper<std::runtime_error>("wat");
113+
EXPECT_NE(ewDiff, ew);
114+
EXPECT_NE(ewDiff, ewSame);
115+
#endif
116+
}
117+
103118
TEST(ExceptionWrapper, tryAndCatchTest) {
104119
auto ew4 = try_and_catch([] { throw 17; });
105120
EXPECT_TRUE(bool(ew4));

0 commit comments

Comments
 (0)