Giter Club home page Giter Club logo

result's People

Contributors

nashenas88 avatar oktal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

result's Issues

Replace void-OK with dummy structs

Right now this library contains two versions of Result: one with normal Ok enum and another with void one.

It may be a short-term convenience for callers (simple Ok() suffices if there's nothing of value to return). However:

  • Essentially there are two versions of each struct and function: double effort for maintenance
  • void is an incomplete type and thus presents distant problems for callers (like #6)

Which begs a question: do we really need special casing for void? My proposal is:

  • Bar void from Ok
  • Provide a dummy type alias for empty tuple (std::tuple<>) / empty struct (struct {}) and relevant Ok (using OK = Ok<Dummy>)
  • Include special macro for convenient lambda creation (e.g. DUMMY_CB for [&](const Dummy&)

This will lead to a closer-to-Rust Ok construction in the form of OK({}) and eliminate any void-related template issues.

TRY macro does not work with Result<void, E>

TRY macro fails when we have void associated with Ok (and rightfully so, since assigning void makes no sense).

Perhaps a separate macro for simple error propagation and static_assert for more informative failure?

in expansion of macro 'TRY'

result.h:631:14: note: candidate: template<class U> const U& details::Storage<void, E>::get() const [with U = U; E = int]
     const U& get() const {
              ^~~
result.h:631:14: note:   template argument deduction/substitution failed:
result.h: In substitution of 'template<class U> const U& details::Storage<void, E>::get() const [with U = void]':
result.h:631:14: error: forming reference to void
result.h:636:8: note: candidate: template<class U> U& details::Storage<void, E>::get() [with U = U; E = int]
     U& get() {
        ^~~
result.h:636:8: note:   template argument deduction/substitution failed:
result.h: In substitution of 'template<class U> U& details::Storage<void, E>::get() [with U = void]':
result.h:636:8: error: forming reference to void

Return value missing in `operator==`

result/result.h

Lines 862 to 873 in fee9af7

template<typename T, typename E>
bool operator==(const Result<T, E>& lhs, const Result<T, E>& rhs) {
static_assert(concept::EqualityComparable<T>::value, "T must be EqualityComparable for Result to be comparable");
static_assert(concept::EqualityComparable<E>::value, "E must be EqualityComparable for Result to be comparable");
if (lhs.isOk() && rhs.isOk()) {
return lhs.storage().template get<T>() == rhs.storage().template get<T>();
}
if (lhs.isErr() && rhs.isErr()) {
return lhs.storage().template get<E>() == rhs.storage().template get<E>();
}
}

Shouldn't a simple return false; in the end fix it?

Select A License

Currently there is no mention of how you wish to license this software. Therefore, technically (under some interpretations), it is in violation of copyright law for others to make a copy.

I'd think it'd be nice for the community if you explicitly set the license.

For a single-file header, I'd recommend a very permissive license, such as the UNLICENSE or MIT.

The project looks good, thanks!

Allow alternatives to `std::terminate`

Currently several functions will call std::terminate on failure. It would be beneficial to allow users to customize this behavior, or possibly switch to using an exception (e.g., illegal state) so the user can catch it and then decide what to do next. While this would not be ideal, there may be circumstances where terminating is extremely inappropriate as there won't be a chance to do a proper cleanup.

add nodiscard attribute

template<typename R, typename E>
class
#if __cplusplus >= 201703L
[[nodiscard]]
#endif
Result {

};

This is c++17 feature and will show warning if you will ignore the Result

No way to extract Err value.

It seems the only way to retrieve the value within the Err is to call through to the storage struct. In Rust, this is done with a match, but there's nothing exactly like that in C++. Could you add an unwrapErr or add documentation on the proper way to extract values like you would with match in Rust?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.