result<R, S>

Header file result.hpp

namespace outcome_v2_xxx
{
    namespace policy
    {
        template <class T, class EC, class E>
        using default_policy = std::conditional_t<std::is_void<EC>::value && std::is_void<E>::value, terminate, std::conditional_t<trait::has_error_code_v<EC>, error_code_throw_as_system_error<T, EC, E>, std::conditional_t<trait::has_exception_ptr_v<EC> || trait::has_exception_ptr_v<E>, exception_ptr_rethrow<T, EC, E>, all_narrow> >>;
    }

    template <class T>
    using is_result = 'hidden';

    template <class T>static constexpr bool is_result_v = detail::is_result<std::decay_t<T>>::value;

    namespace hooks
    {
        template <class T, class U>
        constexpr void hook_result_construction(T*, U&&) noexcept;

        template <class T, class U>
        constexpr void hook_result_copy_construction(T*, U&&) noexcept;

        template <class T, class U>
        constexpr void hook_result_move_construction(T*, U&&) noexcept;

        template <class T, class U, class ... Args>
        constexpr void hook_result_in_place_construction(T*, in_place_type_t<U>, Args &&...) noexcept;

        template <class R, class S, class NoValuePolicy>
        constexpr uint16_t spare_storage('hidden' const* r) noexcept;

        template <class R, class S, class NoValuePolicy>
        constexpr void set_spare_storage('hidden'* r, uint16_t v) noexcept;
    }

    template <class R, class S, class NoValuePolicy>
    class result;

    template <class R, class S, class P>
    void swap(result<R, S, P>& a, result<R, S, P>& b) noexcept('hidden');

    static constexpr bool is_result_v = detail::is_result<std::decay_t<T>>::value;

    static constexpr bool is_result_v = detail::is_result<std::decay_t<T>>::value;

    template <class R, class S = std::error_code>
    using unchecked = result<R, S, policy::all_narrow>;

    template <class R, class S = std::error_code>
    using checked = result<R, S, policy::throw_bad_result_access<S>>;
}

Alias template outcome_v2_xxx::policy::default_policy

template <class T, class EC, class E>
using default_policy = std::conditional_t<std::is_void<EC>::value && std::is_void<E>::value, terminate, std::conditional_t<trait::has_error_code_v<EC>, error_code_throw_as_system_error<T, EC, E>, std::conditional_t<trait::has_exception_ptr_v<EC> || trait::has_exception_ptr_v<E>, exception_ptr_rethrow<T, EC, E>, all_narrow> >>;

Default policy selector.


Alias template outcome_v2_xxx::is_result

template <class T>
using is_result = 'hidden';

True if a result


Unexposed entity outcome_v2_xxx::is_result_v

template <class T>static constexpr bool is_result_v = detail::is_result<std::decay_t<T>>::value;

True if a result


Function outcome_v2_xxx::hooks::hook_result_construction

template <class T, class U>
constexpr void hook_result_construction(T*, U&&) noexcept;

The default instantiation hook implementation called when a result is first created by conversion from one of its possible types. Does nothing.

WARNING: The compiler is permitted to elide calls to constructors, and thus this hook may not get called when you think it should!

Parameters

  • — Some result<...> being constructed.

Function outcome_v2_xxx::hooks::hook_result_copy_construction

template <class T, class U>
constexpr void hook_result_copy_construction(T*, U&&) noexcept;

The default instantiation hook implementation called when a result is created by copying from another result. Does nothing.

WARNING: The compiler is permitted to elide calls to constructors, and thus this hook may not get called when you think it should!

Parameters

  • — Some result<...> being constructed.

Function outcome_v2_xxx::hooks::hook_result_move_construction

template <class T, class U>
constexpr void hook_result_move_construction(T*, U&&) noexcept;

The default instantiation hook implementation called when a result is created by moving from another result. Does nothing.

WARNING: The compiler is permitted to elide calls to constructors, and thus this hook may not get called when you think it should!

Parameters

  • — Some result<...> being constructed.

Function outcome_v2_xxx::hooks::hook_result_in_place_construction

template <class T, class U, class ... Args>
constexpr void hook_result_in_place_construction(T*, in_place_type_t<U>, Args &&...) noexcept;

The default instantiation hook implementation called when a result is created by in place construction. Does nothing.

WARNING: The compiler is permitted to elide calls to constructors, and thus this hook may not get called when you think it should!

Parameters

  • — Some result<...> being constructed.
  • — The type of in place construction occurring.

Function outcome_v2_xxx::hooks::spare_storage

template <class R, class S, class NoValuePolicy>
constexpr uint16_t spare_storage('hidden' const* r) noexcept;

Retrieves the 16 bits of spare storage in result/outcome.


Function outcome_v2_xxx::hooks::set_spare_storage

template <class R, class S, class NoValuePolicy>
constexpr void set_spare_storage('hidden'* r, uint16_t v) noexcept;

Sets the 16 bits of spare storage in result/outcome.


Class outcome_v2_xxx::result

template <class R, class S, class NoValuePolicy>
class result
{
public:
    //=== Member types ===//
    using value_type = R;

    using error_type = S;

    using value_type_if_enabled = typename base::_value_type;

    using error_type_if_enabled = typename base::_error_type;

    template <class T, class U = S, class V = policy::default_policy<T,U,void>>
    using rebind = result<T, U, V>;

protected:
    struct predicate;

public:
    //=== Default, copy/move constructors and assignment ===//
    result() = delete;

    result(result<R, S, NoValuePolicy>&&) = default;

    result(const result<R, S, NoValuePolicy>&) = default;

    result<R, S, NoValuePolicy>& operator=(result<R, S, NoValuePolicy>&&) = default;

    result<R, S, NoValuePolicy>& operator=(const result<R, S, NoValuePolicy>&) = default;

    ~result() = default;

    template <class T>
    constexpr result(T&& t) noexcept('hidden');

    template <class T>
    constexpr result(T&& t) noexcept('hidden');

    template <class ErrorCondEnum>
    constexpr result(ErrorCondEnum&& t) noexcept('hidden');

    template <class T>
    constexpr result(T&& o);

    template <class T, class U, class V>
    constexpr result(result<T, U, V> const& o) noexcept('hidden');

    template <class T, class U, class V>
    constexpr result(result<T, U, V>&& o) noexcept('hidden');

    template <class ... Args>
    constexpr result(in_place_type_t<outcome_v2_xxx::result::value_type_if_enabled> _, Args &&... args) noexcept('hidden');

    template <class U, class ... Args>
    constexpr result(in_place_type_t<outcome_v2_xxx::result::value_type_if_enabled> _, std::initializer_list<U> il, Args &&... args) noexcept('hidden');

    template <class ... Args>
    constexpr result(in_place_type_t<outcome_v2_xxx::result::error_type_if_enabled> _, Args &&... args) noexcept('hidden');

    template <class U, class ... Args>
    constexpr result(in_place_type_t<outcome_v2_xxx::result::error_type_if_enabled> _, std::initializer_list<U> il, Args &&... args) noexcept('hidden');

    template <class A1, class A2, class ... Args>
    constexpr result(A1&& a1, A2&& a2, Args &&... args) noexcept('hidden');

    constexpr result(success_type<void> const& o) noexcept('hidden');

    template <class T>
    constexpr result(success_type<T> const& o) noexcept('hidden');

    template <class T>
    constexpr result(success_type<T>&& o) noexcept('hidden');

    template <class T>
    constexpr result(failure_type<T> const& o) noexcept('hidden');

    template <class T>
    constexpr result(failure_type<T>&& o) noexcept('hidden');

    void swap(result<R, S, NoValuePolicy>& o) noexcept('hidden');

    auto as_failure() const &;

    auto as_failure() &&;

    using error_type = 'hidden';

    //=== assume_error ===//
    constexpr error_type& assume_error() & noexcept;
    constexpr error_type& assume_error() const & noexcept;
    constexpr error_type&& assume_error() && noexcept;
    constexpr error_type&& assume_error() const && noexcept;

    explicit operator bool() const noexcept;

    constexpr bool has_value() const noexcept;

    constexpr bool has_error() const noexcept;

    constexpr bool has_exception() const noexcept;

    constexpr bool has_failure() const noexcept;

    template <class T, class U, class V>
    constexpr bool operator==('hidden' const& o) const noexcept('hidden');

    template <class T>
    constexpr bool operator==(success_type<T> const& o) const noexcept('hidden');

    constexpr bool operator==(success_type<void> const& o) const noexcept;

    template <class T>
    constexpr bool operator==(failure_type<T, void> const& o) const noexcept('hidden');

    template <class T, class U, class V>
    constexpr bool operator!=('hidden' const& o) const noexcept('hidden');

    template <class T>
    constexpr bool operator!=(success_type<T> const& o) const noexcept('hidden');

    constexpr bool operator!=(success_type<void> const& o) const noexcept;

    template <class T>
    constexpr bool operator!=(failure_type<T, void> const& o) const noexcept('hidden');
};

Used to return from functions either (i) a successful value (ii) a cause of failure. constexpr capable.

Any R (value_type) state can be observed using the member functions .value() and .assume_value(). Any S (error_type) state can be observed using the member functions .error() and .assume_error().

NoValuePolicy defaults to a policy selected according to the characteristics of type S:

  1. If .value() called when there is no value_type but there is an error_type:
  1. If .error() called when there is no error_type:
  • If trait::has_error_code_v<S>, or if trait::has_exception_ptr_v<S>, or if S is void, do throw bad_result_access()

  • If S is none of the above, then it is undefined behaviour [policy::all_narrow]

Template parameters

  • R — The optional type of the successful result (use void to disable). Cannot be a reference, a in_place_type_t<>, success<>, failure<>, an array, a function or non-destructible.
  • S — The optional type of the failure result (use void to disable). Must be either void or DefaultConstructible. Cannot be a reference, a in_place_type_t<>, success<>, failure<>, an array, a function or non-destructible.
  • NoValuePolicy — Policy on how to interpret type S when a wide observation of a not present value occurs.

Function outcome_v2_xxx::result::assume_error

(1) constexpr error_type& assume_error() & noexcept;

(2) constexpr error_type& assume_error() const & noexcept;

(3) constexpr error_type&& assume_error() && noexcept;

(4) constexpr error_type&& assume_error() const && noexcept;

Access error without runtime checks.

Preconditions: The result to have a failed state, otherwise it is undefined behaviour.

Returns: Reference to the held error_type according to overload.


Conversion operator outcome_v2_xxx::result::operator bool

explicit operator bool() const noexcept;

Checks if has value.

Returns: True if has value.


Function outcome_v2_xxx::result::has_value

constexpr bool has_value() const noexcept;

Checks if has value.

Returns: True if has value.


Function outcome_v2_xxx::result::has_error

constexpr bool has_error() const noexcept;

Checks if has error.

Returns: True if has error.


Function outcome_v2_xxx::result::has_exception

constexpr bool has_exception() const noexcept;

Checks if has exception.

Returns: True if has exception.


Function outcome_v2_xxx::result::has_failure

constexpr bool has_failure() const noexcept;

Checks if has error or exception.

Returns: True if has error or exception.


Function outcome_v2_xxx::result::operator==

template <class T, class U, class V>
constexpr bool operator==('hidden' const& o) const noexcept('hidden');

True if equal to the other result.

Effects: If a valid expression to do so, calls the operator== operation on each of the two stored items returning true if both are true. Otherwise returns false.

Throws: Any exception the individual operator== operations might throw.

Parameters

  • o — The other result to compare to.

Function outcome_v2_xxx::result::operator==

template <class T>
constexpr bool operator==(success_type<T> const& o) const noexcept('hidden');

True if equal to the success type sugar.

Effects: If a valid expression to do so, calls the operator== operation on the successful item returning true if equal. Otherwise returns false.

Throws: Any exception the operator== operation might throw.

Parameters

  • o — The success type sugar to compare to.

Function outcome_v2_xxx::result::operator==

constexpr bool operator==(success_type<void> const& o) const noexcept;

True if equal to the success type sugar.

Effects: If a valid expression to do so, calls the operator== operation on the successful item returning true if equal. Otherwise returns false.

Throws: Any exception the operator== operation might throw.

Parameters

  • o — The success type sugar to compare to.

Function outcome_v2_xxx::result::operator==

template <class T>
constexpr bool operator==(failure_type<T, void> const& o) const noexcept('hidden');

True if equal to the failure type sugar.

Effects: If a valid expression to do so, calls the operator== operation on the failure item returning true if equal. Otherwise returns false.

Throws: Any exception the operator== operation might throw.

Parameters

  • o — The failure type sugar to compare to.

Function outcome_v2_xxx::result::operator!=

template <class T, class U, class V>
constexpr bool operator!=('hidden' const& o) const noexcept('hidden');

True if not equal to the other result.

Effects: If a valid expression to do so, calls the operator!= operation on each of the two stored items, returning true if any are not equal. Otherwise returns true.

Throws: Any exception the individual operator!= operations might throw.

Parameters

  • o — The other result to compare to.

Function outcome_v2_xxx::result::operator!=

template <class T>
constexpr bool operator!=(success_type<T> const& o) const noexcept('hidden');

True if not equal to the success type sugar.

Effects: If a valid expression to do so, calls the operator!= operation on the successful item returning true if not equal. Otherwise returns false.

Throws: Any exception the operator!= operation might throw.

Parameters

  • o — The success type sugar to compare to.

Function outcome_v2_xxx::result::operator!=

constexpr bool operator!=(success_type<void> const& o) const noexcept;

True if not equal to the success type sugar.

Effects: If a valid expression to do so, calls the operator!= operation on the successful item returning true if not equal. Otherwise returns false.

Throws: Any exception the operator!= operation might throw.

Parameters

  • o — The success type sugar to compare to.

Function outcome_v2_xxx::result::operator!=

template <class T>
constexpr bool operator!=(failure_type<T, void> const& o) const noexcept('hidden');

True if not equal to the failure type sugar.

Effects: If a valid expression to do so, calls the operator!= operation on the failure item returning true if not equal. Otherwise returns false.

Throws: Any exception the operator!= operation might throw.

Parameters

  • o — The failure type sugar to compare to.

Type alias outcome_v2_xxx::result::value_type

using value_type = R;

The success type.


Type alias outcome_v2_xxx::result::error_type

using error_type = S;

The failure type.


Type alias outcome_v2_xxx::result::value_type_if_enabled

using value_type_if_enabled = typename base::_value_type;

Used to disable in place type construction when value_type and error_type are ambiguous.


Type alias outcome_v2_xxx::result::error_type_if_enabled

using error_type_if_enabled = typename base::_error_type;

Used to disable in place type construction when value_type and error_type are ambiguous.


Alias template outcome_v2_xxx::result::rebind

template <class T, class U = S, class V = policy::default_policy<T,U,void>>
using rebind = result<T, U, V>;

Used to rebind this result to a different result type.


Struct outcome_v2_xxx::result::predicate

struct predicate
{
    using base = 'hidden';

    template <class T>static constexpr bool enable_value_converting_constructor = !std::is_same<std::decay_t<T>, result>::value && base::template  enable_value_converting_constructor<T>;

    template <class T>static constexpr bool enable_error_converting_constructor = !std::is_same<std::decay_t<T>, result>::value && base::template  enable_error_converting_constructor<T>;

    template <class ErrorCondEnum>static constexpr bool enable_error_condition_converting_constructor = !std::is_same<std::decay_t<ErrorCondEnum>, result>::value && base::template  enable_error_condition_converting_constructor<ErrorCondEnum>;

    template <class T, class U, class V>static constexpr bool enable_compatible_conversion = !std::is_same<result<T, U, V>, result>::value && base::template  enable_compatible_conversion<T, U, V>;

    template <class...Args>static constexpr bool enable_inplace_value_constructor = std::is_void<value_type>::value || std::is_constructible<value_type, Args...>::value;

    template <class...Args>static constexpr bool enable_inplace_error_constructor = std::is_void<error_type>::value || std::is_constructible<error_type, Args...>::value;

    template <class...Args>static constexpr bool enable_inplace_value_error_constructor = base::template  enable_inplace_value_error_constructor<Args...>;

    template <class ... Args>
    using choose_inplace_value_error_constructor = typename base::choose_inplace_value_error_constructor<Args...>;
};

Requirement predicates for result.

Unexposed entity outcome_v2_xxx::result::predicate::enable_value_converting_constructor

template <class T>static constexpr bool enable_value_converting_constructor = !std::is_same<std::decay_t<T>, result>::value && base::template  enable_value_converting_constructor<T>;

Predicate for the value converting constructor to be available.


Unexposed entity outcome_v2_xxx::result::predicate::enable_error_converting_constructor

template <class T>static constexpr bool enable_error_converting_constructor = !std::is_same<std::decay_t<T>, result>::value && base::template  enable_error_converting_constructor<T>;

Predicate for the error converting constructor to be available.


Unexposed entity outcome_v2_xxx::result::predicate::enable_error_condition_converting_constructor

template <class ErrorCondEnum>static constexpr bool enable_error_condition_converting_constructor = !std::is_same<std::decay_t<ErrorCondEnum>, result>::value && base::template  enable_error_condition_converting_constructor<ErrorCondEnum>;

Predicate for the error condition converting constructor to be available.


Unexposed entity outcome_v2_xxx::result::predicate::enable_compatible_conversion

template <class T, class U, class V>static constexpr bool enable_compatible_conversion = !std::is_same<result<T, U, V>, result>::value && base::template  enable_compatible_conversion<T, U, V>;

Predicate for the converting copy constructor from a compatible input to be available.


Unexposed entity outcome_v2_xxx::result::predicate::enable_inplace_value_constructor

template <class...Args>static constexpr bool enable_inplace_value_constructor = std::is_void<value_type>::value || std::is_constructible<value_type, Args...>::value;

Predicate for the inplace construction of value to be available.


Unexposed entity outcome_v2_xxx::result::predicate::enable_inplace_error_constructor

template <class...Args>static constexpr bool enable_inplace_error_constructor = std::is_void<error_type>::value || std::is_constructible<error_type, Args...>::value;

Predicate for the inplace construction of error to be available.



Constructor outcome_v2_xxx::result::result

result() = delete;

Default construction is not permitted.


Constructor outcome_v2_xxx::result::result

result(result<R, S, NoValuePolicy>&&) = default;

Move construction available if value_type and error_type implement it.


Constructor outcome_v2_xxx::result::result

result(const result<R, S, NoValuePolicy>&) = default;

Copy construction available if value_type and error_type implement it.


Function outcome_v2_xxx::result::operator=

result<R, S, NoValuePolicy>& operator=(result<R, S, NoValuePolicy>&&) = default;

Move assignment available if value_type and error_type implement it.


Function outcome_v2_xxx::result::operator=

result<R, S, NoValuePolicy>& operator=(const result<R, S, NoValuePolicy>&) = default;

Copy assignment available if value_type and error_type implement it.


Constructor outcome_v2_xxx::result::result

template <class T>
constexpr result(T&& t) noexcept('hidden');

Implicit converting constructor to a successful result.

Effects: Initialises the result with a value_type.

Requires: Type T is implicitly constructible to value_type, is not implicitly constructible to error_type, and is not result<R, S> and not in_place_type<>.

Throws: Any exception the construction of value_type(T) might throw.

Parameters

  • t — The value from which to initialise the value_type.

Constructor outcome_v2_xxx::result::result

template <class T>
constexpr result(T&& t) noexcept('hidden');

Implicit converting constructor to a failure result.

Effects: Initialises the result with a error_type.

Requires: Type T is implicitly constructible to error_type, is not implicitly constructible to value_type, and is not result<R, S> and not in_place_type<>.

Throws: Any exception the construction of error_type(T) might throw.

Parameters

  • t — The value from which to initialise the error_type.

Constructor outcome_v2_xxx::result::result

template <class ErrorCondEnum>
constexpr result(ErrorCondEnum&& t) noexcept('hidden');

Implicit special error condition converting constructor to a failure result.

Effects: Initialises the result with a error_type constructed via make_error_code(t).

Requires: std::is_error_condition_enum<ErrorCondEnum> must be true, ErrorCondEnum is not implicitly constructible to value_type nor error_type, and is not result<R, S> and not in_place_type<>; Finally, the expression error_type(make_error_code(ErrorCondEnum())) must be valid.

Throws: Any exception the construction of error_type(make_error_code(t)) might throw.

Parameters

  • t — The error condition from which to initialise the error_type.

Constructor outcome_v2_xxx::result::result

template <class T>
constexpr result(T&& o);

Explicit converting constructor from a compatible ValueOrError type.

Effects: Initialises the result with the contents of the compatible input.

Requires: That convert::value_or_error<result, std::decay_t<T>>{}(std::forward<T>(o)) be available. The default implementation will consume T’s matching the ValueOrError concept type. ValueOrError concept matches any type with a value_type, an error_type, a .value(), an .error() and a .has_value().

Parameters

  • o — The input for which a convert::value_or_error<result, std::decay_t<T>>{}(std::forward<T>(o)) is available.

Constructor outcome_v2_xxx::result::result

template <class T, class U, class V>
constexpr result(result<T, U, V> const& o) noexcept('hidden');

Explicit converting copy constructor from a compatible result type.

Effects: Initialises the result with a copy of the compatible result.

Requires: Both result’s value_type and error_type need to be constructible, or the source can be void.

Throws: Any exception the construction of value_type(T) and error_type(U) might throw.

Parameters

  • o — The compatible result.

Constructor outcome_v2_xxx::result::result

template <class T, class U, class V>
constexpr result(result<T, U, V>&& o) noexcept('hidden');

Explicit converting move constructor from a compatible result type.

Effects: Initialises the result with a move of the compatible result.

Requires: Both result’s value_type and error_type need to be constructible, or the source can be void.

Throws: Any exception the construction of value_type(T) and error_type(U) might throw.

Parameters

  • o — The compatible result.

Constructor outcome_v2_xxx::result::result

template <class ... Args>
constexpr result(in_place_type_t<outcome_v2_xxx::result::value_type_if_enabled> _, Args &&... args) noexcept('hidden');

Explicit inplace constructor to a successful result.

Effects: Initialises the result with a value_type.

Requires: value_type is void or Args... are constructible to value_type.

Throws: Any exception the construction of value_type(Args...) might throw.

Parameters

  • _ — Tag type to indicate we are doing in place construction of value_type.
  • args — Arguments with which to in place construct.

Constructor outcome_v2_xxx::result::result

template <class U, class ... Args>
constexpr result(in_place_type_t<outcome_v2_xxx::result::value_type_if_enabled> _, std::initializer_list<U> il, Args &&... args) noexcept('hidden');

Explicit inplace constructor to a successful result.

Effects: Initialises the result with a value_type.

Requires: The initializer list + Args... are constructible to value_type.

Throws: Any exception the construction of value_type(il, Args...) might throw.

Parameters

  • _ — Tag type to indicate we are doing in place construction of value_type.
  • il — An initializer list with which to in place construct.
  • args — Arguments with which to in place construct.

Constructor outcome_v2_xxx::result::result

template <class ... Args>
constexpr result(in_place_type_t<outcome_v2_xxx::result::error_type_if_enabled> _, Args &&... args) noexcept('hidden');

Explicit inplace constructor to a failure result.

Effects: Initialises the result with a error_type.

Requires: error_type is void or Args... are constructible to error_type.

Throws: Any exception the construction of error_type(Args...) might throw.

Parameters

  • _ — Tag type to indicate we are doing in place construction of error_type.
  • args — Arguments with which to in place construct.

Constructor outcome_v2_xxx::result::result

template <class U, class ... Args>
constexpr result(in_place_type_t<outcome_v2_xxx::result::error_type_if_enabled> _, std::initializer_list<U> il, Args &&... args) noexcept('hidden');

Explicit inplace constructor to a failure result.

Effects: Initialises the result with a error_type.

Requires: The initializer list + Args... are constructible to error_type.

Throws: Any exception the construction of error_type(il, Args...) might throw.

Parameters

  • _ — Tag type to indicate we are doing in place construction of error_type.
  • il — An initializer list with which to in place construct.
  • args — Arguments with which to in place construct.

Constructor outcome_v2_xxx::result::result

template <class A1, class A2, class ... Args>
constexpr result(A1&& a1, A2&& a2, Args &&... args) noexcept('hidden');

Implicit inplace constructor to successful or failure result.

Effects: Calls the appropriate in_place_type_t<...> constructor depending on constructibility of args.

Requires: That the args can construct exactly one of value_type or error_type.

Throws: Any exception the in_place_type_t<...> constructor might throw.

Parameters

  • args — Arguments with which to in place construct.

Constructor outcome_v2_xxx::result::result

constexpr result(success_type<void> const& o) noexcept('hidden');

Implicit tagged constructor of a successful result.

Effects: Initialises the result with a default constructed success type.

Requires: value_type to be default constructible, or void.

Throws: Any exception the construction of value_type() might throw.

Parameters

  • o — The compatible success type sugar.

Constructor outcome_v2_xxx::result::result

template <class T>
constexpr result(success_type<T> const& o) noexcept('hidden');

Implicit tagged constructor of a successful result.

Effects: Initialises the result with a copy of the value in the type sugar.

Requires: Both result and success’ value_type need to be constructible, or the source can be void.

Throws: Any exception the construction of value_type(T) might throw.

Parameters

  • o — The compatible success type sugar.

Constructor outcome_v2_xxx::result::result

template <class T>
constexpr result(success_type<T>&& o) noexcept('hidden');

Implicit tagged constructor of a successful result.

Effects: Initialises the result with a move of the value in the type sugar.

Requires: Both result and success’ value_type need to be constructible. The source cannot be void.

Throws: Any exception the construction of value_type(T) might throw.

Parameters

  • o — The compatible success type sugar.

Constructor outcome_v2_xxx::result::result

template <class T>
constexpr result(failure_type<T> const& o) noexcept('hidden');

Implicit tagged constructor of a failure result.

Effects: Initialises the result with a copy of the error in the type sugar.

Requires: Both result and failure’s error_type need to be constructible, or the source can be void.

Throws: Any exception the construction of error_type(T) might throw.

Parameters

  • o — The compatible failure type sugar.

Constructor outcome_v2_xxx::result::result

template <class T>
constexpr result(failure_type<T>&& o) noexcept('hidden');

Implicit tagged constructor of a failure result.

Effects: Initialises the result with a move of the error in the type sugar.

Requires: Both result and failure’s error_type need to be constructible, or the source can be void.

Throws: Any exception the construction of error_type(T) might throw.

Parameters

  • o — The compatible failure type sugar.

Function outcome_v2_xxx::result::swap

void swap(result<R, S, NoValuePolicy>& o) noexcept('hidden');

Swaps this result with another result

Effects: Any R and/or S is swapped along with the metadata tracking them.


Function outcome_v2_xxx::result::as_failure

auto as_failure() const &;

Returns this result as a failure_type with any errored state copied.

Requires: This result to have a failed state, else whatever assume_error() would do.


Function outcome_v2_xxx::result::as_failure

auto as_failure() &&;

Returns this result as a failure_type with any errored state moved.

Requires: This result to have a failed state, else whatever assume_error() would do.



Function outcome_v2_xxx::swap

template <class R, class S, class P>
void swap(result<R, S, P>& a, result<R, S, P>& b) noexcept('hidden');

Specialise swap for result.

Effects: Calls a.swap(b).


Alias template outcome_v2_xxx::unchecked

template <class R, class S = std::error_code>
using unchecked = result<R, S, policy::all_narrow>;

An “unchecked” edition of result<T, E> which does no special handling of specific E types at all.

Attempting to access T when there is an E results in nothing happening at all, it is treated with a narrow contract (i.e. undefined behaviour).


Alias template outcome_v2_xxx::checked

template <class R, class S = std::error_code>
using checked = result<R, S, policy::throw_bad_result_access<S>>;

A “checked” edition of result<T, E> which resembles fairly closely a std::expected<T, E>.

Attempting to access T when there is an E results in bad_result_access<E> being thrown. Nothing else.

Note that this approximates the proposed expected<T, E> up for standardisation, see the FAQ for more detail.