Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/razshare/cpp-result
- Owner: razshare
- License: mit
- Created: 2024-07-23T11:50:47.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-07-23T12:12:57.000Z (6 months ago)
- Last Synced: 2025-01-08T15:18:15.498Z (5 days ago)
- Language: C++
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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;
```