Success/Failure

Header file success_failure.hpp

namespace outcome_v2_xxx
{
    namespace policy
    {
        template <class T>
        constexpr auto error_code(T&& v);

        template <class T>
        constexpr auto exception_ptr(T&& v);

        template <class Error>
        constexpr void throw_as_system_error_with_payload(Error const& error);
    }

    namespace trait
    {
        template <class T>
        struct has_error_code;

        template <class T>constexpr bool has_error_code_v = has_error_code<T>::value;

        template <class T>
        struct has_exception_ptr;

        template <class T>constexpr bool has_exception_ptr_v = has_exception_ptr<T>::value;
    }

    template <class T>
    struct success_type;

    template <>
    struct success_type<void>;

    constexpr success_type<void> success() noexcept;

    template <class T>
    constexpr success_type<std::decay_t<T>> success(T&& v);

    template <class EC = std::error_code, class E = void>
    struct failure_type;

    template <class EC>
    struct failure_type<EC, void>;

    template <class E>
    struct failure_type<void, E>;

    template <class EC>
    constexpr failure_type<std::decay_t<EC>> failure(EC&& v);

    template <class EC, class E>
    constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(EC&& v, E&& w);
}

Function outcome_v2_xxx::policy::error_code

template <class T>
constexpr auto error_code(T&& v);

Used by policies to extract a std::error_code from some input T via ADL discovery of some make_error_code(T) function.


Function outcome_v2_xxx::policy::exception_ptr

template <class T>
constexpr auto exception_ptr(T&& v);

Used by policies to extract a std::exception_ptr from some input T via ADL discovery of some make_exception_ptr(T) function.


Function outcome_v2_xxx::policy::throw_as_system_error_with_payload

template <class Error>
constexpr void throw_as_system_error_with_payload(Error const& error);

Override to define what the policies which throw a system error with payload ought to do for some particular result.error().


Struct outcome_v2_xxx::trait::has_error_code

template <class T>
struct has_error_code
{
};

Trait for whether a free function make_error_code(T) returning a std::error_code exists or not.

Also returns true if std::error_code is convertible from T.


Unexposed entity outcome_v2_xxx::trait::has_error_code_v

template <class T>constexpr bool has_error_code_v = has_error_code<T>::value;

Trait for whether a free function make_error_code(T) returning a std::error_code exists or not.

Also returns true if std::error_code is convertible from T.


Struct outcome_v2_xxx::trait::has_exception_ptr

template <class T>
struct has_exception_ptr
{
};

Trait for whether a free function make_exception_ptr(T) returning a std::exception_ptr exists or not.

Also returns true if std::exception_ptr is convertible from T.


Unexposed entity outcome_v2_xxx::trait::has_exception_ptr_v

template <class T>constexpr bool has_exception_ptr_v = has_exception_ptr<T>::value;

Trait for whether a free function make_exception_ptr(T) returning a std::exception_ptr exists or not.

Also returns true if std::exception_ptr is convertible from T.


Struct outcome_v2_xxx::success_type

template <class T>
struct success_type
{
    using value_type = T;

    //=== Default, copy/move constructors and assignment ===//
    success_type() = default;

    success_type(const success_type<T>&) = default;

    success_type(success_type<T>&&) = default;

    success_type<T>& operator=(const success_type<T>&) = default;

    success_type<T>& operator=(success_type<T>&&) = default;

    ~success_type() = default;

    template <class U, typename = std::enable_if_t<!std::is_same<success_type,std::decay_t<U>>::value>>
    constexpr success_type(U&& v);

    //=== success_type_value ===//
    constexpr value_type& value() &;
    constexpr value_type& value() const &;
    constexpr value_type&& value() &&;
    constexpr value_type&& value() const &&;
};

Type sugar for implicitly constructing a result<> with a successful state.

Type alias outcome_v2_xxx::success_type::value_type

using value_type = T;

The type of the successful state.


Constructor outcome_v2_xxx::success_type::success_type

success_type() = default;

Default constructor


Constructor outcome_v2_xxx::success_type::success_type

success_type(const success_type<T>&) = default;

Copy constructor


Constructor outcome_v2_xxx::success_type::success_type

success_type(success_type<T>&&) = default;

Move constructor


Function outcome_v2_xxx::success_type::operator=

success_type<T>& operator=(const success_type<T>&) = default;

Copy assignment


Function outcome_v2_xxx::success_type::operator=

success_type<T>& operator=(success_type<T>&&) = default;

Move assignment


Destructor outcome_v2_xxx::success_type::~success_type

~success_type() = default;

Destructor


Constructor outcome_v2_xxx::success_type::success_type

template <class U, typename = std::enable_if_t<!std::is_same<success_type,std::decay_t<U>>::value>>
constexpr success_type(U&& v);

Initialising constructor

Requires: That U is not success_type.


Function outcome_v2_xxx::success_type::value

(1) constexpr value_type& value() &;

(2) constexpr value_type& value() const &;

(3) constexpr value_type&& value() &&;

(4) constexpr value_type&& value() const &&;

Access value.

Returns: Reference to the held value_type according to overload.



Struct outcome_v2_xxx::success_type

template <>
struct success_type<void>
{
    using value_type = void;
};

Type sugar for implicitly constructing a result<> with a successful state.

Type alias outcome_v2_xxx::success_type::value_type

using value_type = void;

The type of the successful state.



Function outcome_v2_xxx::success

constexpr success_type<void> success() noexcept;

Returns type sugar for implicitly constructing a result<T> with a successful state, default constructing T if necessary.


Function outcome_v2_xxx::success

template <class T>
constexpr success_type<std::decay_t<T>> success(T&& v);

Returns type sugar for implicitly constructing a result<T> with a successful state.

Effects: Copies or moves the successful state supplied into the returned type sugar.


Struct outcome_v2_xxx::failure_type

template <class EC = std::error_code, class E = void>
struct failure_type
{
    using error_type = EC;

    using exception_type = E;

    //=== Default, copy/move constructors and assignment ===//
    failure_type() = default;

    failure_type(const failure_type<EC, E>&) = default;

    failure_type(failure_type<EC, E>&&) = default;

    failure_type<EC, E>& operator=(const failure_type<EC, E>&) = default;

    failure_type<EC, E>& operator=(failure_type<EC, E>&&) = default;

    ~failure_type() = default;

    template <class U, class V>
    constexpr failure_type(U&& u, V&& v);

    //=== failure_type_error ===//
    constexpr error_type& error() &;
    constexpr error_type& error() const &;
    constexpr error_type&& error() &&;
    constexpr error_type&& error() const &&;

    //=== failure_type_exception ===//
    constexpr exception_type& exception() &;
    constexpr exception_type& exception() const &;
    constexpr exception_type&& exception() &&;
    constexpr exception_type&& exception() const &&;
};

Type sugar for implicitly constructing a result<> with a failure state of error code and exception.

Type alias outcome_v2_xxx::failure_type::error_type

using error_type = EC;

The type of the error code


Type alias outcome_v2_xxx::failure_type::exception_type

using exception_type = E;

The type of the exception


Constructor outcome_v2_xxx::failure_type::failure_type

failure_type() = default;

Default constructor


Constructor outcome_v2_xxx::failure_type::failure_type

failure_type(const failure_type<EC, E>&) = default;

Copy constructor


Constructor outcome_v2_xxx::failure_type::failure_type

failure_type(failure_type<EC, E>&&) = default;

Move constructor


Function outcome_v2_xxx::failure_type::operator=

failure_type<EC, E>& operator=(const failure_type<EC, E>&) = default;

Copy assignment


Function outcome_v2_xxx::failure_type::operator=

failure_type<EC, E>& operator=(failure_type<EC, E>&&) = default;

Move assignment


Destructor outcome_v2_xxx::failure_type::~failure_type

~failure_type() = default;

Destructor


Constructor outcome_v2_xxx::failure_type::failure_type

template <class U, class V>
constexpr failure_type(U&& u, V&& v);

Initialising constructor


Function outcome_v2_xxx::failure_type::error

(1) constexpr error_type& error() &;

(2) constexpr error_type& error() const &;

(3) constexpr error_type&& error() &&;

(4) constexpr error_type&& error() const &&;

Access error.

Returns: Reference to the held error_type according to overload.


Function outcome_v2_xxx::failure_type::exception

(1) constexpr exception_type& exception() &;

(2) constexpr exception_type& exception() const &;

(3) constexpr exception_type&& exception() &&;

(4) constexpr exception_type&& exception() const &&;

Access exception.

Returns: Reference to the held exception_type according to overload.



Struct outcome_v2_xxx::failure_type

template <class EC>
struct failure_type<EC, void>
{
    using error_type = EC;

    using exception_type = void;

    //=== Default, copy/move constructors and assignment ===//
    failure_type() = default;

    failure_type(failure_type<type-parameter-0-0, void> const&) = default;

    failure_type(failure_type<type-parameter-0-0, void>&&) = default;

    failure_type<type-parameter-0-0, void>& operator=(failure_type<type-parameter-0-0, void> const&) = default;

    failure_type<type-parameter-0-0, void>& operator=(failure_type<type-parameter-0-0, void>&&) = default;

    ~failure_type() = default;

    template <class U, typename = std::enable_if_t<!std::is_same<failure_type,std::decay_t<U>>::value>>
    constexpr failure_type(U&& u);

    //=== failure_type_error2 ===//
    constexpr error_type& error() &;
    constexpr error_type& error() const &;
    constexpr error_type&& error() &&;
    constexpr error_type&& error() const &&;
};

Type sugar for implicitly constructing a result<> with a failure state of error code.

Type alias outcome_v2_xxx::failure_type::error_type

using error_type = EC;

The type of the error code


Type alias outcome_v2_xxx::failure_type::exception_type

using exception_type = void;

The type of the exception


Constructor outcome_v2_xxx::failure_type::failure_type

failure_type() = default;

Default constructor


Constructor outcome_v2_xxx::failure_type::failure_type

failure_type(failure_type<type-parameter-0-0, void> const&) = default;

Copy constructor


Constructor outcome_v2_xxx::failure_type::failure_type

failure_type(failure_type<type-parameter-0-0, void>&&) = default;

Move constructor


Function outcome_v2_xxx::failure_type::operator=

failure_type<type-parameter-0-0, void>& operator=(failure_type<type-parameter-0-0, void> const&) = default;

Copy assignment


Function outcome_v2_xxx::failure_type::operator=

failure_type<type-parameter-0-0, void>& operator=(failure_type<type-parameter-0-0, void>&&) = default;

Move assignment


Destructor outcome_v2_xxx::failure_type::~failure_type

~failure_type() = default;

Destructor


Constructor outcome_v2_xxx::failure_type::failure_type

template <class U, typename = std::enable_if_t<!std::is_same<failure_type,std::decay_t<U>>::value>>
constexpr failure_type(U&& u);

Initialising constructor

Requires: That U is not failure_type.


Function outcome_v2_xxx::failure_type::error

(1) constexpr error_type& error() &;

(2) constexpr error_type& error() const &;

(3) constexpr error_type&& error() &&;

(4) constexpr error_type&& error() const &&;

Access error.

Returns: Reference to the held error_type according to overload.



Struct outcome_v2_xxx::failure_type

template <class E>
struct failure_type<void, E>
{
    using error_type = void;

    using exception_type = E;

    //=== Default, copy/move constructors and assignment ===//
    failure_type() = default;

    failure_type(failure_type<void, type-parameter-0-0> const&) = default;

    failure_type(failure_type<void, type-parameter-0-0>&&) = default;

    failure_type<void, type-parameter-0-0>& operator=(failure_type<void, type-parameter-0-0> const&) = default;

    failure_type<void, type-parameter-0-0>& operator=(failure_type<void, type-parameter-0-0>&&) = default;

    ~failure_type() = default;

    template <class V, typename = std::enable_if_t<!std::is_same<failure_type,std::decay_t<V>>::value>>
    constexpr failure_type(V&& v);

    //=== failure_type_exception2 ===//
    constexpr exception_type& exception() &;
    constexpr exception_type& exception() const &;
    constexpr exception_type&& exception() &&;
    constexpr exception_type&& exception() const &&;
};

Type sugar for implicitly constructing a result<> with a failure state of exception.

Type alias outcome_v2_xxx::failure_type::error_type

using error_type = void;

The type of the error code


Type alias outcome_v2_xxx::failure_type::exception_type

using exception_type = E;

The type of the exception


Constructor outcome_v2_xxx::failure_type::failure_type

failure_type() = default;

Default constructor


Constructor outcome_v2_xxx::failure_type::failure_type

failure_type(failure_type<void, type-parameter-0-0> const&) = default;

Copy constructor


Constructor outcome_v2_xxx::failure_type::failure_type

failure_type(failure_type<void, type-parameter-0-0>&&) = default;

Move constructor


Function outcome_v2_xxx::failure_type::operator=

failure_type<void, type-parameter-0-0>& operator=(failure_type<void, type-parameter-0-0> const&) = default;

Copy assignment


Function outcome_v2_xxx::failure_type::operator=

failure_type<void, type-parameter-0-0>& operator=(failure_type<void, type-parameter-0-0>&&) = default;

Move assignment


Destructor outcome_v2_xxx::failure_type::~failure_type

~failure_type() = default;

Destructor


Constructor outcome_v2_xxx::failure_type::failure_type

template <class V, typename = std::enable_if_t<!std::is_same<failure_type,std::decay_t<V>>::value>>
constexpr failure_type(V&& v);

Initialising constructor

Requires: That V is not failure_type.


Function outcome_v2_xxx::failure_type::exception

(1) constexpr exception_type& exception() &;

(2) constexpr exception_type& exception() const &;

(3) constexpr exception_type&& exception() &&;

(4) constexpr exception_type&& exception() const &&;

Access exception.

Returns: Reference to the held exception_type according to overload.



Function outcome_v2_xxx::failure

template <class EC>
constexpr failure_type<std::decay_t<EC>> failure(EC&& v);

Returns type sugar for implicitly constructing a result<T> with a failure state.

Effects: Copies or moves the failure state supplied into the returned type sugar.


Function outcome_v2_xxx::failure

template <class EC, class E>
constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(EC&& v, E&& w);

Returns type sugar for implicitly constructing a result<T> with a failure state.

Effects: Copies or moves the failure state supplied into the returned type sugar.