| master branch | develop branch |
|---|---|
CTest dashboard: https://my.cdash.org/index.php?project=Boost.Outcome
All tests passing source tarballs: https://github.com/ned14/outcome/releases
Documentation: https://ned14.github.io/outcome/
Outcome is a lightweight C++14 library designed to handle and report function failures efficiently. It provides types outcome<T> and result<T> as an alternative or complement to exception handling, enabling explicit and predictable control of error conditions.
Use cases include:
- Environments where C++ exceptions are not suitable due to performance or policy.
- Systems requiring static control flow analysis for safety and correctness.
- Software architectures that propagate errors across threads without exceptions.
- Codebases compiled with
-fno-exceptionsor legacy systems without exception safety design.
Repository: https://github.com/thomgit9/outcome
Default branch: develop
License: Apache 2.0 / Boost Software License 1.0 dual license
Visibility: public
Maintainers:
- ned14 (primary author and maintainer)
Outcome can be used either as a regular multi-header library or as a single header implementation.
Option 1 – Single header inclusion:
You may include the generated single header file directly in your project:
# Linux
wget https://github.com/ned14/outcome/raw/master/single-header/outcome.hpp
# BSD
fetch https://github.com/ned14/outcome/raw/master/single-header/outcome.hpp
# Using curl
curl -O -J -L https://github.com/ned14/outcome/raw/master/single-header/outcome.hppIf debugging using Microsoft Visual Studio, consider including the debugger visualization file in your build for improved IDE integration.
Option 2 – CMake integration:
git clone https://github.com/thomgit9/outcome.git
cd outcome
cmake -B build
cmake --build buildCTest integration is available, reporting to CDash.
Outcome provides robust result types for safer error handling.
Typical usage examples:
#include "outcome.hpp"
using namespace OUTCOME_V2_NAMESPACE;
result<int> divide(int a, int b)
{
if(b == 0) return error_code(std::errc::invalid_argument);
return a / b;
}
int main()
{
auto r = divide(10, 2);
if(r.has_value())
std::cout << "Result: " << r.value() << std::endl;
else
std::cerr << "Error: " << r.error().message() << std::endl;
}Outcome integrates with modern C++ constructs, supports coroutines, and interoperates with Boost.System and Standard error handling.
| Name | File | Description | Inputs | Outputs |
|---|---|---|---|---|
result<T> |
include/outcome/result.hpp |
Represents a value or an error condition. | T, ErrorCode |
Value T or ErrorCode |
outcome<T> |
include/outcome/outcome.hpp |
Extends result<T> to include exception and error storage. |
T, ErrorCode, Exception |
Value T or error/exception information |
basic_result |
include/outcome/basic_result.hpp |
Low-level generic implementation of result<T>. |
Template type parameters | Typed result wrapper |
basic_outcome |
include/outcome/basic_outcome.hpp |
Customizable core of outcome<T>. |
Template type parameters | Structured result including error/exception states |
try<T> |
include/outcome/try.hpp |
Provides macro helpers for concise error propagation. | Expression or callable returning result<T> |
Returns unwrapped success or propagates failure |
status_bits() |
abi-compliance/src/main.cpp |
Returns ABI-locked internal status bitfields for outcome. |
None | Internal status mask |
value_storage_int() |
abi-compliance/src/main.cpp |
ABI-locked storage accessor for trivial value types. | value_storage_trivial<int, long>& |
Returns identical object |
value_storage_NonTrivialType() |
abi-compliance/src/main.cpp |
ABI-locked storage accessor for non-trivial types. | value_storage_nontrivial<NonTrivialType, int>& |
Returns identical object |
Commits and tags in this repository can be verified using the following PGP key:
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2
mDMEVvMacRYJKwYBBAHaRw8BAQdAp+Qn6djfxWQYtAEvDmv4feVmGALEQH/pYpBC
llaXNQe0WE5pYWxsIERvdWdsYXMgKHMgW3VuZGVyc2NvcmVdIHNvdXJjZWZvcmdl
IHthdH0gbmVkcHJvZCBbZG90XSBjb20pIDxzcGFtdHJhcEBuZWRwcm9kLmNvbT6I
eQQTFggAIQUCVvMacQIbAwULCQgHAgYVCAkKCwIEFgIDAQIeAQIXgAAKCRCELDV4
Zvkgx4vwAP9gxeQUsp7ARMFGxfbR0xPf6fRbH+miMUg2e7rYNuHtLQD9EUoR32We
V8SjvX4r/deKniWctvCi5JccgfUwXkVzFAk=
=puFk
-----END PGP PUBLIC KEY BLOCK-----