41 Result(Value&& value) noexcept : mValue(
std::move(value)), mErrFlags(kErrFlagsNone) {}
43 Result(
const Value& value) : mValue(value), mErrFlags(kErrFlagsNone) {}
48 if (mErrFlags == kErrFlagsNone) {
49 new (&mValue) Value(
std::move(other.mValue));
55 Result(
const Result& other) noexcept : mErrFlags(other.mErrFlags) {
56 if (mErrFlags == kErrFlagsNone) {
57 new (&mValue) Value(other.mValue);
64 typename ErrorCodeEnum,
66 Result(ErrorCodeEnum err) noexcept : mErr(err), mErrFlags(kErrFlagHaveErr) {}
71 if (mErrFlags == kErrFlagsNone) {
80 if (mErrFlags == kErrFlagsNone) {
81 if (other.mErrFlags == kErrFlagsNone) {
88 if (other.mErrFlags == kErrFlagsNone) {
91 new (&mValue) Value(
std::move(other.mValue));
96 mErrFlags = other.mErrFlags;
101 if (mErrFlags == kErrFlagsNone) {
102 if (other.mErrFlags == kErrFlagsNone) {
103 mValue = other.mValue;
109 if (other.mErrFlags == kErrFlagsNone) {
112 new (&mValue) Value(other.mValue);
117 mErrFlags = other.mErrFlags;
121 explicit operator bool()
const noexcept {
122 return mErrFlags == kErrFlagsNone;
126 if (mErrFlags != kErrFlagsNone) {
127 throwBadResultAccess();
133 if (mErrFlags != kErrFlagsNone) {
134 throwBadResultAccess();
139 auto operator->() -> Value* {
140 if (mErrFlags != kErrFlagsNone) {
141 throwBadResultAccess();
146 auto operator->()
const ->
const Value* {
147 if (mErrFlags != kErrFlagsNone) {
148 throwBadResultAccess();
154 if (mErrFlags != kErrFlagsNone) {
160 [[nodiscard]]
auto logged()
const noexcept ->
bool {
161 return (mErrFlags & kErrFlagLogged) != 0;
164 [[nodiscard]]
auto skipped()
const noexcept ->
bool {
165 return (mErrFlags & kErrFlagSkipped) != 0;
169 [[noreturn]]
void throwBadResultAccess()
const {
170#if (__has_feature__cxx_exceptions)
182 static constexpr uint8_t kErrFlagsNone = 0x00;
183 static constexpr uint8_t kErrFlagHaveErr = 0x01;
184 static constexpr uint8_t kErrFlagLogged = 0x02;
185 static constexpr uint8_t kErrFlagSkipped = 0x04;
192 enum class Construct { kToken };
194 explicit constexpr success_t(Construct) {}
203 Result() noexcept : mDummy(), mErrFlags(kErrFlagsNone) {}
208 if (mErrFlags != kErrFlagsNone) {
213 Result(
const Result& other) noexcept : mErrFlags(other.mErrFlags) {
214 if (mErrFlags != kErrFlagsNone) {
220 typename ErrorCodeEnum,
222 Result(ErrorCodeEnum err) noexcept : mErr(err), mErrFlags(kErrFlagHaveErr) {}
226 Result(success_t) noexcept : mDummy(), mErrFlags(kErrFlagsNone) {}
229 if (mErrFlags != kErrFlagsNone) {
236 if (mErrFlags == kErrFlagsNone) {
237 if (other.mErrFlags != kErrFlagsNone) {
241 if (other.mErrFlags == kErrFlagsNone) {
248 mErrFlags = other.mErrFlags;
253 if (mErrFlags == kErrFlagsNone) {
254 if (other.mErrFlags != kErrFlagsNone) {
258 if (other.mErrFlags == kErrFlagsNone) {
265 mErrFlags = other.mErrFlags;
270 if (mErrFlags != kErrFlagsNone) {
274 mErrFlags = kErrFlagsNone;
278 explicit operator bool()
const noexcept {
279 return mErrFlags == kErrFlagsNone;
282 auto operator==(success_t)
const noexcept ->
bool {
283 return mErrFlags == kErrFlagsNone;
287 if (mErrFlags != kErrFlagsNone) {
293 [[nodiscard]]
auto logged()
const noexcept ->
bool {
294 return (mErrFlags & kErrFlagLogged) != 0;
297 [[nodiscard]]
auto skipped()
const noexcept ->
bool {
298 return (mErrFlags & kErrFlagSkipped) != 0;
302 [[noreturn]]
static void throwBadResultAccess() {
303#if (__has_feature__cxx_exceptions)
315 static constexpr uint8_t kErrFlagsNone = 0x00;
316 static constexpr uint8_t kErrFlagHaveErr = 0x01;
317 static constexpr uint8_t kErrFlagLogged = 0x02;
318 static constexpr uint8_t kErrFlagSkipped = 0x04;
324static constexpr success_t
kSuccess{success_t::Construct::kToken};
327template <
typename T,
typename Enable = std::ostream&>
334void stringifyForStream(T& t,
341void stringifyForStream(T& t,
343 typename std::enable_if<!supports_ostream<T>::value, T>::type* = 0) {
344 os <<
"[" <<
typeid(t).name() <<
"]";
353 os << instance.error().message();
355 tiltfive::stringifyForStream(*instance, os);
364 os << instance.error().message();
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
constexpr complex< _Tp > & operator=(const _Tp &)
constexpr bool operator==(const complex< _Tp > &__x, const complex< _Tp > &__y)
error_code make_error_code(future_errc __errc) noexcept
auto declval() noexcept -> decltype(__declval< _Tp >(0))
constexpr _OI move(_II __first, _II __last, _OI __result)
void terminate() noexcept
logic_error(const string &__arg) _GLIBCXX_TXN_SAFE
virtual const char * what() const noexcept
Throw when attempting to access a bad result.
Specialization of tiltfive::Result for functions with 'no return'.
Templated return type with support for error conditions.
static constexpr success_t kSuccess
Indicates 'success' for a Result<void> function.
std::ostream & operator<<(std::ostream &os, const tiltfive::Result< T > &instance)
Support for writing tiltfive::Result<> to an std::ostream.