46 const T&
value() const & {
return value_; }
47 T&&
value() && {
return std::move(value_); }
62 const E&
value() const & {
return value_; }
63 E&&
value() && {
return std::move(value_); }
75template <
typename T,
typename E>
77 static_assert(!std::is_same_v<T, E>,
"Result<T,E> requires distinct T and E");
86 requires std::is_default_constructible_v<T>
88 new (&storage_.value) T();
93 new (&storage_.value) T(std::move(ok).
value());
98 new (&storage_.error) E(std::move(err).
value());
102 if (has_value_)
new (&storage_.value) T(
other.storage_.value);
103 else new (&storage_.error) E(
other.storage_.error);
107 std::is_nothrow_move_constructible_v<E>)
108 : has_value_(
other.has_value_) {
109 if (has_value_)
new (&storage_.value) T(std::move(
other.storage_.value));
110 else new (&storage_.error) E(std::move(
other.storage_.error));
117 if (
this != &
other) {
118 if (
other.has_value_) {
119 T tmp(
other.storage_.value);
122 new (&storage_.value) T(std::move(tmp));
124 E tmp(
other.storage_.error);
127 new (&storage_.error) E(std::move(tmp));
134 std::is_nothrow_move_constructible_v<T> &&
135 std::is_nothrow_move_constructible_v<E>) {
136 if (
this != &
other) {
137 if (
other.has_value_) {
138 T tmp(std::move(
other.storage_.value));
141 new (&storage_.value) T(std::move(tmp));
143 E tmp(std::move(
other.storage_.error));
146 new (&storage_.error) E(std::move(tmp));
157 explicit operator bool() const noexcept {
return has_value_; }
158 bool is_err() const noexcept {
return !has_value_; }
166 T&
value() & {
return storage_.value; }
167 const T&
value() const & {
return storage_.value; }
168 T&&
value() && {
return std::move(storage_.value); }
176 template <
typename U>
178 return has_value_ ? storage_.value
179 :
static_cast<T
>(std::forward<U>(fallback));
186 E&
error() & {
return storage_.error; }
187 const E&
error() const & {
return storage_.error; }
188 E&&
error() && {
return std::move(storage_.error); }
199 void destroy() noexcept {
200 if (has_value_) storage_.value.~T();
201 else storage_.error.~E();
230 if (!has_value_)
new (&
error_) E(
other.error_ref());
234 : has_value_(
other.has_value_) {
235 if (!has_value_)
new (&
error_) E(std::move(
other.error_ref()));
241 if (
this != &
other) {
242 if (
other.has_value_) {
246 E tmp(
other.error_ref());
249 new (&
error_) E(std::move(tmp));
256 if (
this != &
other) {
257 if (
other.has_value_) {
261 E tmp(std::move(
other.error_ref()));
264 new (&
error_) E(std::move(tmp));
273 explicit operator bool() const noexcept {
return has_value_; }
274 bool is_err() const noexcept {
return !has_value_; }
282 E&
error() & {
return error_ref(); }
283 const E&
error() const & {
return error_ref(); }
284 E&&
error() && {
return std::move(error_ref()); }
295 E& error_ref() noexcept {
return error_; }
296 const E& error_ref() const noexcept {
return error_; }
298 void destroy() noexcept {
299 if (!has_value_) error_.~E();
Wrap a value as a failure result.
Definition result.hpp:58
Err(E value)
Definition result.hpp:60
E & value() &
Definition result.hpp:61
const E & value() const &
Definition result.hpp:62
E && value() &&
Definition result.hpp:63
Wrap a value as a success result.
Definition result.hpp:42
T && value() &&
Definition result.hpp:47
Ok(T value)
Definition result.hpp:44
T & value() &
Definition result.hpp:45
const T & value() const &
Definition result.hpp:46
Result(const Result &other)
Definition result.hpp:229
Result(Result &&other) noexcept(std::is_nothrow_move_constructible_v< E >)
Definition result.hpp:233
Result(Err< E > err)
Definition result.hpp:225
E error_type
Definition result.hpp:220
E error_
Definition result.hpp:291
E & error() &
Definition result.hpp:282
bool has_value() const noexcept
Definition result.hpp:272
~Result()
Definition result.hpp:270
void value() const noexcept
Present so generic code can call value() uniformly.
Definition result.hpp:279
void value_type
Definition result.hpp:219
E && error() &&
Definition result.hpp:284
Result & operator=(const Result &other)
Definition result.hpp:240
Result & operator=(Result &&other) noexcept(std::is_nothrow_move_constructible_v< E >)
Definition result.hpp:255
bool is_err() const noexcept
Definition result.hpp:274
const E & error() const &
Definition result.hpp:283
Result() noexcept
Success.
Definition result.hpp:223
ContentFragmentError error_type
Definition result.hpp:81
bool is_err() const noexcept
Definition result.hpp:158
Result(Err< E > err)
Definition result.hpp:96
const E & error() const &
Definition result.hpp:187
const T & value() const &
Definition result.hpp:167
Result()
Definition result.hpp:85
Result(Ok< T > ok)
Definition result.hpp:91
Result(const Result &other)
Definition result.hpp:101
Result & operator=(Result &&other) noexcept(std::is_nothrow_move_constructible_v< T > &&std::is_nothrow_move_constructible_v< E >)
Definition result.hpp:133
Result(Result &&other) noexcept(std::is_nothrow_move_constructible_v< T > &&std::is_nothrow_move_constructible_v< E >)
Definition result.hpp:106
Result & operator=(const Result &other)
Definition result.hpp:116
E & error() &
Definition result.hpp:186
T && value() &&
Definition result.hpp:168
~Result()
Definition result.hpp:152
T * operator->()
Definition result.hpp:172
const T * operator->() const
Definition result.hpp:173
T & operator*() &
Definition result.hpp:170
T & value() &
Definition result.hpp:166
bool has_value() const noexcept
Definition result.hpp:156
E && error() &&
Definition result.hpp:188
ContentProgramFragment value_type
Definition result.hpp:80
T value_or(U &&fallback) const &
Return the held value, or fallback when this is an error.
Definition result.hpp:177
const T & operator*() const &
Definition result.hpp:171
Definition generated_event_source.hpp:33
@ other
Definition udev_monitor.hpp:26