Skip to content
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
merged 71 commits into from
Jan 28, 2022

Conversation

PragmaTwice
Copy link
Contributor

@PragmaTwice PragmaTwice commented Nov 19, 2021

oneflow::maybe::Variant:

oneflow::maybe::Optional:

  • optimized storage for scalar type
  • support reference type, unlike std::optional
  • support monadic operations Map, AndThen and OrElse
  • hide .Value() (only exposed to JUST via friend class), unlike std::optional (cleaner than oneflow::Optional)
  • no std::shared_ptr, unlike oneflow::Optional for non-scalar type

flexiable stacked error types

  • StackedErrorTraits<T> for a type T to become a StackedError
  • simple::StackedError and simple::NoStackError as demo error types
  • and even std::unique_ptr<simple::StackedError> can be an Error because we have StackedErrorTraits<std::unique_ptr<T>>
  • define your own stacked error types easily (just need some member functions OR provide StackedErrorTraits<your type>)

oneflow::maybe::Maybe:

  • support custom error type
  • hide .Value() (only exposed to JUST via friend class)
  • support monadic operations Map, AndThen
  • no std::shared_ptr, unlike oneflow::Maybe for non-scalar type (use Maybe<std::shared_ptr<T>, E> if you want shared_ptr)

customizable JUST macro:

  • support Maybe and Optional
  • customizable via JustTraits, then we can write JUST(some_shared_ptr)
  • NO GLOG REQUIRED, you can use your favorite logging library, and just need to define some behavior in error types

@PragmaTwice PragmaTwice requested review from oneflow-ci-bot and removed request for oneflow-ci-bot January 27, 2022 16:03
@PragmaTwice PragmaTwice requested review from oneflow-ci-bot and removed request for oneflow-ci-bot January 28, 2022 02:04
@PragmaTwice PragmaTwice requested review from oneflow-ci-bot and removed request for oneflow-ci-bot January 28, 2022 05:22
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot January 28, 2022 06:03
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot January 28, 2022 08:54
@PragmaTwice PragmaTwice requested review from oneflow-ci-bot and removed request for oneflow-ci-bot January 28, 2022 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants