-
Notifications
You must be signed in to change notification settings - Fork 754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Standalone Maybe: refactor Variant, Optional, Maybe and more #6820
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PragmaTwice
requested review from
lixinqi,
daquexian,
hjchen2 and
jackalcooper
November 19, 2021 08:46
PragmaTwice
requested review from
oneflow-ci-bot
and removed request for
oneflow-ci-bot
January 27, 2022 16:03
PragmaTwice
requested review from
oneflow-ci-bot
and removed request for
oneflow-ci-bot
January 28, 2022 02:04
PragmaTwice
requested review from
oneflow-ci-bot
and removed request for
oneflow-ci-bot
January 28, 2022 05:22
oneflow-ci-bot
requested review from
oneflow-ci-bot
and removed request for
oneflow-ci-bot
January 28, 2022 06:03
oneflow-ci-bot
requested review from
oneflow-ci-bot
and removed request for
oneflow-ci-bot
January 28, 2022 08:54
PragmaTwice
requested review from
oneflow-ci-bot
and removed request for
oneflow-ci-bot
January 28, 2022 09:53
oneflow-ci-bot
requested review from
oneflow-ci-bot
and removed request for
oneflow-ci-bot
January 28, 2022 10:58
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
oneflow::maybe::Variant
:.Visit()
: unlikestd::visit
forstd::variant
, we use a hybrid policy between trivial recursion and binary search to retain full optimization (see https://github.com/PragmaTwice/oneflow/blob/maybe/oneflow/maybe/variant.h#L40 for details)Optional
:NullOpt
for bothstd::monostate
andstd::nullopt
(see https://github.com/PragmaTwice/oneflow/blob/maybe/oneflow/maybe/utility.h#L29 for details)std::shared_ptr
, unlikeSharedOrScalar
,EitherPtr
in oneflowoneflow::maybe::Optional
:std::optional
Map
,AndThen
andOrElse
.Value()
(only exposed toJUST
via friend class), unlikestd::optional
(cleaner thanoneflow::Optional
)std::shared_ptr
, unlikeoneflow::Optional
for non-scalar typeflexiable stacked error types
StackedErrorTraits<T>
for a type T to become a StackedErrorsimple::StackedError
andsimple::NoStackError
as demo error typesstd::unique_ptr<simple::StackedError>
can be an Error because we haveStackedErrorTraits<std::unique_ptr<T>>
StackedErrorTraits<your type>
)oneflow::maybe::Maybe
:.Value()
(only exposed toJUST
via friend class)Map
,AndThen
std::shared_ptr
, unlikeoneflow::Maybe
for non-scalar type (useMaybe<std::shared_ptr<T>, E>
if you want shared_ptr)customizable JUST macro:
Maybe
andOptional
JustTraits
, then we can writeJUST(some_shared_ptr)