Before we begin

Outcome v2 namespace

It is recommended that you refer to entities from this Outcome v2 via the following namespace alias:

namespace outcome = OUTCOME_V2_NAMESPACE;
View this code on Github

On standalone Outcome only, as patches and modifications are applied to this library, namespaces get permuted in order to not to cause binary incompatibility. At some point namespace outcome_v2 will be defined, and this will be the preferred namespace. Until then OUTCOME_V2_NAMESPACE denotes the most recently updated version, getting closer to outcome_v2.

On Boost.Outcome only, as Boost provides no binary compatibility across releases, OUTCOME_V2_NAMESPACE always expands into boost::outcome_v2.

Online compilers

If you’ve never used them before, you will find Godbolt and Wandbox invaluable. These let you play with C++ inside your web browser.

Most of the source code snippets in Outcome have a link in their top right to the original source code on github. You can copy and paste this source code into Godbolt (if you wish to study the assembler generated) or Wandbox (if you wish to run the program).

Godbolt

Godbolt is invaluable for visualising online the assembler generated for a piece of C++, for all the major compilers and CPU architectures.

Standalone Outcome is built into Godbolt! In the right hand pane toolbar, click the libraries dropdown (currently third from the right, looks like a book), find Outcome and choose the version you want.

After this is selected, you can #include any of these editions of Outcome:

<outcome-basic.hpp>
An inclusion of basic_outcome.hpp + try.hpp which includes as few system headers as possible in order to give an absolute minimum compile time impact edition of Outcome. See https://github.com/ned14/stl-header-heft.
<outcome-experimental.hpp>
An inclusion of experimental/status_outcome.hpp + try.hpp which is the low compile time impact of the basic edition combined with status_code from https://ned14.github.io/status-code/. If you are on an embedded system where binary bloat must be absolutely avoided, and don't mind the potentially unstable status_code, this is definitely the edition for you.
<outcome.hpp>
An inclusion of outcome.hpp which brings in all the specialisations for the std STL types, plus iostreams support. If you don't know which edition to use, you should use this one, it ought to "just work".

Here is the first tutorial topic’s source code loaded into Godbolt: https://godbolt.org/z/4of3c8

Wandbox

Wandbox lets you place a third party header into a separate tab. It also comes with a recent Boost libraries. Either technique can be used to explore Outcome.

Here is the first tutorial topic’s source code loaded into Wandbox: https://wandbox.org/permlink/sJoeKHXSyCU5Avft