Skip to content

Commit

Permalink
Back out "chained" conversion from Expected
Browse files Browse the repository at this point in the history
Summary: I introduced this in D49215070, but since then ended up building an opaque wrapper on top of `Expected`, which means that the only known use-case of this conversion no longer exists.

Reviewed By: yfeldblum

Differential Revision: D58036054

fbshipit-source-id: 224d6b9a09cc2f47732ab9b28305289817aaceea
  • Loading branch information
snarkmaster authored and facebook-github-bot committed Jun 19, 2024
1 parent 113a478 commit d92c78a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 34 deletions.
21 changes: 0 additions & 21 deletions folly/Expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -977,27 +977,6 @@ class Expected final : expected_detail::ExpectedStorage<Value, Error> {
this->assign(std::move(that));
}

// Implicit then-chaining conversion: if `Expected<Value, Error>` can be
// constructed from `V`, then we can directly convert `Expected<V, E>` to
// `Expected<Value, Error>`.
//
// Specifically, this allows a user-defined conversions of `V` to
// `Expected<Value, Error>` to work as desired with range-based iteration
// over containers of `Expected<V, E>`.
template <
class V,
class E FOLLY_REQUIRES_TRAILING(
!std::is_same<Expected<V, E>, Expected>::value &&
!std::is_constructible<Value, V&&>::value &&
std::is_constructible<Expected<Value, Error>, V&&>::value &&
std::is_constructible<Error, E&&>::value)>
/* implicit */ Expected(Expected<V, E> that)
: Base{expected_detail::EmptyTag{}} {
this->assign(std::move(that).then([](V&& v) -> Expected<Value, Error> {
return Expected<Value, Error>{v};
}));
}

FOLLY_REQUIRES(std::is_copy_constructible<Value>::value)
constexpr /* implicit */ Expected(const Value& val) noexcept(
noexcept(Value(val)))
Expand Down
13 changes: 0 additions & 13 deletions folly/test/ExpectedTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,19 +970,6 @@ TEST(Expected, TestUnique) {
}));
}

struct ConvertibleNum {
/*implicit*/ operator Expected<int, E>() const { return num_; }
int num_;
};

TEST(Expected, TestChainedConversion) {
auto vs =
std::vector<Expected<ConvertibleNum, E>>{ConvertibleNum{.num_ = 137}};
for (Expected<int, E> v : vs) {
ASSERT_EQ(137, *v);
}
}

struct ConvertibleError {
struct E1 {};
struct E2 {};
Expand Down

0 comments on commit d92c78a

Please sign in to comment.