28 #ifndef HERMES_HERMES_COMMON_RESULT_H
29 #define HERMES_HERMES_COMMON_RESULT_H
55 template<
class T,
class E = HeResult>
73 new(
reinterpret_cast<E *
>(&err_)) E(err.value);
78 new(
reinterpret_cast<T *
>(&value_)) T(v);
83 new(
reinterpret_cast<T *
>(&value_)) T(std::move(v));
94 *
this = std::move(other);
110 new(
reinterpret_cast<T *
>(&value_)) T(other.
value());
112 new(
reinterpret_cast<E *
>(&err_)) E(other.status());
122 new(
reinterpret_cast<T *
>(&value_)) T(std::move(other.value()));
124 new(
reinterpret_cast<E *
>(&err_)) E(std::move(other.status()));
133 new(
reinterpret_cast<T *
>(&value_)) T(v);
142 new(
reinterpret_cast<T *
>(&value_)) T(std::move(v));
178 return *
reinterpret_cast<T *
>(&value_);
183 return *
reinterpret_cast<const T *
>(&value_);
191 typename std::aligned_storage<
sizeof(T),
alignof(T)>::type value_;
Holds a valid object or an error.
Definition: result.h:56
HERMES_DEVICE_CALLABLE Result & operator=(Result &&other) noexcept
Move assignment.
Definition: result.h:118
HERMES_DEVICE_CALLABLE const T & value() const
Gets value's const reference.
Definition: result.h:182
HERMES_DEVICE_CALLABLE const T & operator*() const
Gets value const reference.
Definition: result.h:157
HERMES_DEVICE_CALLABLE Result(T &&v)
Move value constructor.
Definition: result.h:82
HERMES_DEVICE_CALLABLE Result & operator=(T &&v)
Move value assignment.
Definition: result.h:139
HERMES_DEVICE_CALLABLE Result(Result &&other) noexcept
Move constructor.
Definition: result.h:93
HERMES_DEVICE_CALLABLE Result & operator=(const Result &other)
Copy assignment.
Definition: result.h:106
HERMES_DEVICE_CALLABLE Result(const Result &other)
Copy constructor.
Definition: result.h:88
HERMES_DEVICE_CALLABLE T valueOr(const T &v) const
Gets value copy (if present)
Definition: result.h:174
HERMES_DEVICE_CALLABLE T * operator->()
Gets value pointer.
Definition: result.h:148
static HERMES_DEVICE_CALLABLE Result< T, E > error(E e)
Definition: result.h:64
HERMES_DEVICE_CALLABLE Result(const T &v)
Value constructor.
Definition: result.h:77
HERMES_DEVICE_CALLABLE T & operator*()
Gets value reference.
Definition: result.h:154
HERMES_DEVICE_CALLABLE Result & operator=(const T &v)
Value assignment.
Definition: result.h:130
HERMES_DEVICE_CALLABLE const T * operator->() const
Gets const value pointer.
Definition: result.h:151
HERMES_DEVICE_CALLABLE void reset()
Destroys stored value (if present)
Definition: result.h:164
HERMES_DEVICE_CALLABLE T & value()
Gets value's reference.
Definition: result.h:177
HERMES_DEVICE_CALLABLE Result(const UnexpectedResultType< E > &err={})
Definition: result.h:72
#define HERMES_DEVICE_CALLABLE
Specifies that the function can be called from both host and device sides.
Definition: defs.h:45