Commit b0eb4087 authored by Alexander Kindyakov's avatar Alexander Kindyakov Committed by Facebook Github Bot

Fix up error in generic definition of folly::swap

Summary:
- Fix up wrong order of template arguments in Expected generic
  - Create tests to check up all 3 forms of swap for Expected

Reviewed By: ericniebler

Differential Revision: D9013316

fbshipit-source-id: d4cebd83b268a4c5c551ac970f67b598f117fa73
parent b9d2332c
...@@ -1362,8 +1362,8 @@ inline bool operator>=( ...@@ -1362,8 +1362,8 @@ inline bool operator>=(
/** /**
* swap Expected values * swap Expected values
*/ */
template <class Error, class Value> template <class Value, class Error>
void swap(Expected<Error, Value>& lhs, Expected<Value, Error>& rhs) noexcept( void swap(Expected<Value, Error>& lhs, Expected<Value, Error>& rhs) noexcept(
expected_detail::StrictAllOf<IsNothrowSwappable, Value, Error>::value) { expected_detail::StrictAllOf<IsNothrowSwappable, Value, Error>::value) {
lhs.swap(rhs); lhs.swap(rhs);
} }
......
...@@ -297,11 +297,11 @@ TEST(Expected, Order) { ...@@ -297,11 +297,11 @@ TEST(Expected, Order) {
EXPECT_EQ(vect, expected); EXPECT_EQ(vect, expected);
} }
TEST(Expected, Swap) { TEST(Expected, SwapMethod) {
Expected<std::string, E> a; Expected<std::string, E> a;
Expected<std::string, E> b; Expected<std::string, E> b;
swap(a, b); a.swap(b);
EXPECT_FALSE(a.hasValue()); EXPECT_FALSE(a.hasValue());
EXPECT_FALSE(b.hasValue()); EXPECT_FALSE(b.hasValue());
...@@ -310,7 +310,7 @@ TEST(Expected, Swap) { ...@@ -310,7 +310,7 @@ TEST(Expected, Swap) {
EXPECT_FALSE(b.hasValue()); EXPECT_FALSE(b.hasValue());
EXPECT_EQ("hello", a.value()); EXPECT_EQ("hello", a.value());
swap(a, b); b.swap(a);
EXPECT_FALSE(a.hasValue()); EXPECT_FALSE(a.hasValue());
EXPECT_TRUE(b.hasValue()); EXPECT_TRUE(b.hasValue());
EXPECT_EQ("hello", b.value()); EXPECT_EQ("hello", b.value());
...@@ -319,7 +319,63 @@ TEST(Expected, Swap) { ...@@ -319,7 +319,63 @@ TEST(Expected, Swap) {
EXPECT_TRUE(a.hasValue()); EXPECT_TRUE(a.hasValue());
EXPECT_EQ("bye", a.value()); EXPECT_EQ("bye", a.value());
swap(a, b); a.swap(b);
EXPECT_EQ("hello", a.value());
EXPECT_EQ("bye", b.value());
}
TEST(Expected, StdSwapFunction) {
Expected<std::string, E> a;
Expected<std::string, E> b;
std::swap(a, b);
EXPECT_FALSE(a.hasValue());
EXPECT_FALSE(b.hasValue());
a = "greeting";
EXPECT_TRUE(a.hasValue());
EXPECT_FALSE(b.hasValue());
EXPECT_EQ("greeting", a.value());
std::swap(a, b);
EXPECT_FALSE(a.hasValue());
EXPECT_TRUE(b.hasValue());
EXPECT_EQ("greeting", b.value());
a = "goodbye";
EXPECT_TRUE(a.hasValue());
EXPECT_EQ("goodbye", a.value());
std::swap(a, b);
EXPECT_EQ("greeting", a.value());
EXPECT_EQ("goodbye", b.value());
}
TEST(Expected, FollySwapFunction) {
Expected<std::string, E> a;
Expected<std::string, E> b;
folly::swap(a, b);
EXPECT_FALSE(a.hasValue());
EXPECT_FALSE(b.hasValue());
a = "salute";
EXPECT_TRUE(a.hasValue());
EXPECT_FALSE(b.hasValue());
EXPECT_EQ("salute", a.value());
folly::swap(a, b);
EXPECT_FALSE(a.hasValue());
EXPECT_TRUE(b.hasValue());
EXPECT_EQ("salute", b.value());
a = "adieu";
EXPECT_TRUE(a.hasValue());
EXPECT_EQ("adieu", a.value());
folly::swap(a, b);
EXPECT_EQ("salute", a.value());
EXPECT_EQ("adieu", b.value());
} }
TEST(Expected, Comparisons) { TEST(Expected, Comparisons) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment