Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/razshare/cpp-result

Safe error management in C++ using Result<T>, which is an Either<L,R> in disguise.
https://github.com/razshare/cpp-result

Last synced: 1 day ago
JSON representation

Safe error management in C++ using Result<T>, which is an Either<L,R> in disguise.

Awesome Lists containing this project

README

        

# What is this?

This is an implementation of `Result` in C++.

# Opinions & Usage

Do not throw exceptions in your code.

Instead, use the provided `success()` and `failure()` functions and return `Error` objects.

Both functions make use of generic templates, so they are type safe.

```c++
auto [name, error] = success("world").unwrap();
```

Here, `name_result` is of type `Result`.

Every single time your have `Result` on your hands, you **must** unwrap it and check the error.

This gives you type safety and ensures you always know, at the language server level and compile time, when something can go wrong.

```c++
//auto [name, error] = success("world").unwrap();
auto [name, error] = failure("Something is wrong.").unwrap();
if(error.code > 0){
// Something is wrong.
return;
}

std::cout << "hello " << name;
```