Define a custom code domain

Firstly let’s alias the experimental Outcome namespace into something less tedious to type, declare our custom status code type, and get started on defining the custom status code domain implementation.

namespace outcome_e = OUTCOME_V2_NAMESPACE::experimental;

// To define a `file_io_error` which participates in the P1028 world
// of `std::error`, we must first declare, then define, a custom code
// domain which extends `posix_code` (the std error coding for POSIX
// failures). The following is fairly standard boilerplate for defining
// a custom code domain. It is analogous to defining a custom `std::error_category`.

class _file_io_error_domain;
// We define `file_io_error` to be the status code whose domain is `_file_io_error_domain`.
using file_io_error = outcome_e::status_code<_file_io_error_domain>;

// Now we define `_file_io_error_domain`.
class _file_io_error_domain : public outcome_e::posix_code::domain_type
{
  using _base = typename outcome_e::posix_code::domain_type;
View this code on Github

Note that we inherit from outcome_e::posix_code::domain_type, not from outcome_e::status_code_domain. We thus reuse most of the implementation of outcome_e::posix_code::domain_type rather than implementing required functionality. If you would like to see a fuller treatment of defining a custom status code domain from scratch, see this worked example here.

You may find looking at the API reference documentation for status_code_domain useful in the next few pages .