All Projects → basicpp17 → result17

basicpp17 / result17

Licence: MIT license
A rust like Result type for modern C++

Programming Languages

C++
36643 projects - #6 most used programming language
QML
638 projects

Projects that are alternatives of or similar to result17

result
A lightweight C++11-compatible error-handling mechanism
Stars: ✭ 121 (+830.77%)
Mutual labels:  error-handling, result-type
Happy
the alchemist's happy path with elixir
Stars: ✭ 37 (+184.62%)
Mutual labels:  monad, error-handling
ts-belt
🔧 Fast, modern, and practical utility library for FP in TypeScript.
Stars: ✭ 439 (+3276.92%)
Mutual labels:  monad, result-type
Ok jose
Pipe elixir functions that match ok/error tuples or custom patterns.
Stars: ✭ 91 (+600%)
Mutual labels:  monad, error-handling
Perhaps
A monad, perhaps.
Stars: ✭ 35 (+169.23%)
Mutual labels:  monad, error-handling
sealed-monad
Scala library for nice business logic oriented, for-comprehension-style error handling
Stars: ✭ 16 (+23.08%)
Mutual labels:  monad, error-handling
alea
Coq library for reasoning on randomized algorithms [maintainers=@anton-trunov,@volodeyka]
Stars: ✭ 20 (+53.85%)
Mutual labels:  monad
babel-errors
Nicer error messages for Babel
Stars: ✭ 15 (+15.38%)
Mutual labels:  error-handling
raygun4py
Python provider for Raygun
Stars: ✭ 18 (+38.46%)
Mutual labels:  error-handling
30minLearningJavaScriptMonad
30分でわかるJavaScriptプログラマのためのモナド入門
Stars: ✭ 15 (+15.38%)
Mutual labels:  monad
bugsnag
Report errors with Bugsnag 🐛
Stars: ✭ 37 (+184.62%)
Mutual labels:  error-handling
ScrapeM
A monadic web scraping library
Stars: ✭ 17 (+30.77%)
Mutual labels:  monad
friendly-error
Show uncaught errors friendly in Node.js.
Stars: ✭ 75 (+476.92%)
Mutual labels:  error-handling
nested-error-stacks
A node.js module for creating Error objects with nested Errors in stacktraces
Stars: ✭ 86 (+561.54%)
Mutual labels:  error-handling
meiga
🧙 A simple, typed and monad-based Result type for Python.
Stars: ✭ 24 (+84.62%)
Mutual labels:  result-type
maybe-baby
Minimize defensive coding. A JavaScript implementation of the Maybe monad.
Stars: ✭ 42 (+223.08%)
Mutual labels:  monad
custom-exception-middleware
Middleware to catch custom or accidental exceptions
Stars: ✭ 30 (+130.77%)
Mutual labels:  error-handling
optionals
Rust-like error handling and options for TypeScript and Deno!
Stars: ✭ 97 (+646.15%)
Mutual labels:  error-handling
node-graceful-shutdown
Gracefully shutdown your modular NodeJS application.
Stars: ✭ 20 (+53.85%)
Mutual labels:  error-handling
monas
🦋 Scala monads for javascript
Stars: ✭ 21 (+61.54%)
Mutual labels:  monad

C++17 Result

Build Status

A Rust inspired Result<V,E> type for C++17.

template<typename V, typename E>
struct Result;

basically a sophisticated wrapper for:

std::variant< ok<V>, error<E> >

Usage synopsis

auto fn() -> Result<std::ifstream, string>;
auto splitLines(std::stringstream&) -> std::vector<string>;

int main() {
    auto f = openFile("hello.txt")
        .orMap([](auto&&) { return openFile("fallback.txt"); }) // invoked only on error
        .andMap([](auto&& in) -> Result<std::stringstream, string> { // invoked only if successful
            std::stringstream out;
            out << in.rdbuf();
            if (out.str().empty()) return error("empty file"s);
            return ok(move(out));
        })
        .andMap(&splitLines) // adds no errors
        .orMap([](auto) -> Result<std::vector<string>, string> {
            return ok(std::vector<string>{});
        });
    for (auto &l : f.unwrap()) std::cout << l << '\n'; // we are sure we have a value
}

see Result.test.cpp for a working example.

Requirements

You will need a C++17 compiler.

  • GCC 8.x
  • Clang 8.x + libc++
  • MSVC2017/2019
  • googletest is optional to run the tests

Links

Status

Even though this seems to work, it is only a proof of concept.

  • it works
  • std::variant is unusable slow for this kind of use case.
  • std::reference_wrapper does not allow comparisons.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].