20#ifndef WG14_RESULT_STATUS_CODE_RESULT_H
21#define WG14_RESULT_STATUS_CODE_RESULT_H
38#if __STDC_VERSION__ >= 202000L
55 (1U << 0U) | (1U << 3U),
57 (1U << 1U) | (1U << 3U),
59 (2U << 1U) | (1U << 3U),
68 (1U << 1U) | (1U << 4U),
70 (3U << 1U) | (1U << 4U),
74 (1U << 1U) | (1U << 3U) | (1U << 4U),
77 (3U << 1U) | (1U << 3U) | (1U << 4U),
87 (2U << 1U) | (1U << 5U),
89 (3U << 1U) | (1U << 5U),
101 (2U << 1U) | (1U << 3U) | (1U << 5U),
104 (3U << 1U) | (1U << 3U) | (1U << 5U),
107 (1U << 4U) | (1U << 5U),
114 (3U << 1U) | (1U << 4U) | (1U << 5U),
118 (1U << 1U) | (1U << 3U) | (1U << 4U) | (1U << 5U),
121 (3U << 1U) | (1U << 3U) | (1U << 4U) | (1U << 5U),
125 union WG14_RESULT_PREFIX(result_flags)
136#if __STDC_VERSION__ >= 201100L
137 _Static_assert(
sizeof(
union WG14_RESULT_PREFIX(result_flags)) ==
139 "result_flags is not the size it is supposed to be!");
140 _Static_assert(__alignof(
union WG14_RESULT_PREFIX(
result_flags)) ==
142 "result_flags does not have the alignment it is supposed to!");
146 typedef struct WG14_RESULT_PREFIX(result_with_void)
148 union WG14_RESULT_PREFIX(result_flags) _flags_;
151#if __STDC_VERSION__ >= 201100L
154 "Result is not the size it is supposed to be!");
157 "Result does not have the alignment it is supposed to!");
162 WG14_RESULT_PREFIX(result_void_make_success)(void)
164 struct WG14_RESULT_PREFIX(result_with_void)
166 WG14_RESULT_PREFIX(status_code_system_empty)};
171 WG14_RESULT_PREFIX(result_void_make_failure)(
174 struct WG14_RESULT_PREFIX(result_with_void)
180#define WG14_RESULT_DECLARE(T, name) \
181 struct WG14_RESULT_PREFIX(result_with_##name) \
184 union WG14_RESULT_PREFIX(result_flags) _flags_; \
185 WG14_RESULT_PREFIX(status_code_system) error; \
187 WG14_RESULT_INLINE struct WG14_RESULT_PREFIX(result_with_##name) \
188 WG14_RESULT_PREFIX(result_##name##_make_success)(T val) \
190 struct WG14_RESULT_PREFIX(result_with_##name) \
192 {WG14_RESULT_PREFIX(result_status_flag_have_value)}, \
193 WG14_RESULT_PREFIX(status_code_system_empty)}; \
196 WG14_RESULT_INLINE struct WG14_RESULT_PREFIX(result_with_##name) \
197 WG14_RESULT_PREFIX(result_##name##_make_failure)( \
198 WG14_RESULT_PREFIX(status_code_system) err) \
200 struct WG14_RESULT_PREFIX(result_with_##name) ret; \
201 memset(&ret, 0, sizeof(ret)); \
203 ret._flags_.status = WG14_RESULT_PREFIX(result_status_flag_have_error); \
207#define WG14_RESULT(name) struct WG14_RESULT_PREFIX(result_with_##name)
209#define WG14_RESULT_MAKE_SUCCESS(name, ...) \
210 WG14_RESULT_PREFIX(result_##name##_make_success)(__VA_ARGS__)
212#define WG14_RESULT_MAKE_FAILURE(name, ...) \
213 WG14_RESULT_PREFIX(result_##name##_make_failure)(__VA_ARGS__)
215#define WG14_RESULT_HAS_VALUE(...) \
216 ((__VA_ARGS__)._flags_.status_bits & \
217 WG14_RESULT_PREFIX(result_status_flag_have_value))
219#define WG14_RESULT_HAS_ERROR(...) \
220 ((__VA_ARGS__)._flags_.status_bits & \
221 WG14_RESULT_PREFIX(result_status_flag_have_error))
#define WG14_RESULT_INLINE
@ result_status_flag_have_error_exception_lost_consistency_error_is_errno
@ result_status_flag_have_error_exception_error_is_errno
@ result_status_flag_have_error_exception
@ result_status_flag_have_value_lost_consistency
@ result_status_flag_have_moved_from
@ result_status_flag_have_error_error_is_errno
@ result_status_flag_have_value
@ result_status_flag_have_error_exception_moved_from
@ result_status_flag_have_error_error_is_errno_moved_from
@ result_status_flag_none
@ result_status_flag_have_error_exception_lost_consistency_moved_from
@ result_status_flag_have_error_is_errno
@ result_status_flag_have_error_exception_lost_consistency_error_is_errno_moved_from
@ result_status_flag_have_error_lost_consistency_moved_from
@ result_status_flag_have_error_exception_error_is_errno_moved_from
@ result_status_flag_have_lost_consistency
@ result_status_flag_have_error_lost_consistency
@ result_status_flag_have_exception_moved_from
@ result_status_flag_have_value_moved_from
@ result_status_flag_have_error_moved_from
@ result_status_flag_have_value_lost_consistency_moved_from
@ result_status_flag_have_exception_lost_consistency
@ result_status_flag_have_error_is_errno_moved_from
@ result_status_flag_have_error_lost_consistency_error_is_errno_moved_from
@ result_status_flag_have_error_lost_consistency_error_is_errno
@ result_status_flag_have_exception_lost_consistency_moved_from
@ result_status_flag_have_error_exception_lost_consistency
@ result_status_flag_have_exception
@ result_status_flag_have_error
A status_code guaranteed to be able to hold any system error code in full. The payload is always an i...
The flags type within a Result.
enum result_status_flags status
uint16_t spare_storage_value