Skip to content

Commit

Permalink
Make Expected(EmptyTag) ctor quasi-public for coroutine promises
Browse files Browse the repository at this point in the history
Summary: I'm making `folly::exception_wrapper`-centric short-circuiting coroutine on the basis of `Expected`, and the current `PromiseReturn` magic relies on having access to this `EmptyTag` ctor.

Reviewed By: yfeldblum

Differential Revision: D56957309

fbshipit-source-id: 315b4342f101225ff5932db4eb678faab1ecf2cb
  • Loading branch information
snarkmaster authored and facebook-github-bot committed May 11, 2024
1 parent b4ce2cf commit d1e601c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions folly/Expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -1372,13 +1372,23 @@ class Expected final : expected_detail::ExpectedStorage<Value, Error> {
std::move(base()), static_cast<Yes&&>(yes), static_cast<No&&>(no)));
}

// Quasi-private, exposed only for implementing efficient short-circuiting
// coroutines on top of `Expected`. Do NOT use this instead of
// `optional<Expected<>>`, for these reasons:
// - This public ctor again become private in the future.
// - It is incompatible with upcoming `std::expected`.
// - It violates `folly::Expected`'s almost-never-empty guarantee.
// - There's no native `empty()` test -- `uninitializedByException()` is
// always `false` for some value types, and `!hasValue() && !hasError()`
// is less efficient.
explicit Expected(expected_detail::EmptyTag tag) noexcept : Base{tag} {}

private:
friend struct expected_detail::PromiseReturn<Value, Error>;
using EmptyTag = expected_detail::EmptyTag;

explicit Expected(EmptyTag tag) noexcept : Base{tag} {}
// for when coroutine promise return-object conversion is eager
Expected(EmptyTag tag, Expected*& pointer) noexcept : Base{tag} {
Expected(expected_detail::EmptyTag tag, Expected*& pointer) noexcept
: Base{tag} {
pointer = this;
}

Expand Down

0 comments on commit d1e601c

Please sign in to comment.