WG14 result
Loading...
Searching...
No Matches
result.h File Reference
Include dependency graph for result.h:

Go to the source code of this file.

Classes

union  result_flags
 The flags type within a Result. More...
 
struct  result_with_void
 A Result for type void. More...
 

Macros

#define WG14_RESULT_DECLARE(T, name)
 Declare a Result named name with successful type T
 
#define WG14_RESULT(name)   struct WG14_RESULT_PREFIX(result_with_##name)
 The type of a Result named name previously declared.
 
#define WG14_RESULT_MAKE_SUCCESS(name, ...)    WG14_RESULT_PREFIX(result_##name##_make_success)(__VA_ARGS__)
 Make a successful named Result previously declared.
 
#define WG14_RESULT_MAKE_FAILURE(name, ...)    WG14_RESULT_PREFIX(result_##name##_make_failure)(__VA_ARGS__)
 Make a failed named Result previously declared.
 
#define WG14_RESULT_HAS_VALUE(...)
 True if a Result is successful (and contains a value if not void)
 
#define WG14_RESULT_HAS_ERROR(...)
 True if a Result is a failure (and contains an error)
 

Typedefs

typedef struct result_with_void result_with_void
 A Result for type void.
 

Enumerations

enum  result_status_flags {
  result_status_flag_none = 0 , result_status_flag_have_value = (1U << 0U) , result_status_flag_have_error = (1U << 1U) , result_status_flag_have_exception = (2U << 1U) ,
  result_status_flag_have_error_exception = (3U << 1U) , result_status_flag_have_lost_consistency = (1U << 3U) , result_status_flag_have_value_lost_consistency , result_status_flag_have_error_lost_consistency ,
  result_status_flag_have_exception_lost_consistency , result_status_flag_have_error_exception_lost_consistency , result_status_flag_have_error_is_errno = (1U << 4U) , result_status_flag_have_error_error_is_errno ,
  result_status_flag_have_error_exception_error_is_errno , result_status_flag_have_error_lost_consistency_error_is_errno , result_status_flag_have_error_exception_lost_consistency_error_is_errno , result_status_flag_have_moved_from = (1U << 5U) ,
  result_status_flag_have_value_moved_from , result_status_flag_have_error_moved_from , result_status_flag_have_exception_moved_from , result_status_flag_have_error_exception_moved_from ,
  result_status_flag_have_value_lost_consistency_moved_from , result_status_flag_have_error_lost_consistency_moved_from , result_status_flag_have_exception_lost_consistency_moved_from , result_status_flag_have_error_exception_lost_consistency_moved_from ,
  result_status_flag_have_error_is_errno_moved_from , result_status_flag_have_error_error_is_errno_moved_from , result_status_flag_have_error_exception_error_is_errno_moved_from , result_status_flag_have_error_lost_consistency_error_is_errno_moved_from ,
  result_status_flag_have_error_exception_lost_consistency_error_is_errno_moved_from
}
 

Macro Definition Documentation

◆ WG14_RESULT

#define WG14_RESULT (   name)    struct WG14_RESULT_PREFIX(result_with_##name)

The type of a Result named name previously declared.

Definition at line 207 of file result.h.

◆ WG14_RESULT_DECLARE

#define WG14_RESULT_DECLARE (   T,
  name 
)
Value:
struct WG14_RESULT_PREFIX(result_with_##name) \
{ \
T value; \
union WG14_RESULT_PREFIX(result_flags) _flags_; \
WG14_RESULT_PREFIX(status_code_system) error; \
}; \
WG14_RESULT_INLINE struct WG14_RESULT_PREFIX(result_with_##name) \
WG14_RESULT_PREFIX(result_##name##_make_success)(T val) \
{ \
struct WG14_RESULT_PREFIX(result_with_##name) \
ret = {val, \
{WG14_RESULT_PREFIX(result_status_flag_have_value)}, \
WG14_RESULT_PREFIX(status_code_system_empty)}; \
return ret; \
} \
WG14_RESULT_INLINE struct WG14_RESULT_PREFIX(result_with_##name) \
WG14_RESULT_PREFIX(result_##name##_make_failure)( \
WG14_RESULT_PREFIX(status_code_system) err) \
{ \
struct WG14_RESULT_PREFIX(result_with_##name) ret; \
memset(&ret, 0, sizeof(ret)); \
ret.error = err; \
ret._flags_.status = WG14_RESULT_PREFIX(result_status_flag_have_error); \
return ret; \
}
#define WG14_RESULT_INLINE
Definition config.h:63
@ result_status_flag_have_value
Definition result.h:46
@ result_status_flag_have_error
Definition result.h:47
A status_code guaranteed to be able to hold any system error code in full. The payload is always an i...

Declare a Result named name with successful type T

Definition at line 180 of file result.h.

◆ WG14_RESULT_HAS_ERROR

#define WG14_RESULT_HAS_ERROR (   ...)
Value:
((__VA_ARGS__)._flags_.status_bits & \
WG14_RESULT_PREFIX(result_status_flag_have_error))

True if a Result is a failure (and contains an error)

Definition at line 219 of file result.h.

◆ WG14_RESULT_HAS_VALUE

#define WG14_RESULT_HAS_VALUE (   ...)
Value:
((__VA_ARGS__)._flags_.status_bits & \
WG14_RESULT_PREFIX(result_status_flag_have_value))

True if a Result is successful (and contains a value if not void)

Definition at line 215 of file result.h.

◆ WG14_RESULT_MAKE_FAILURE

#define WG14_RESULT_MAKE_FAILURE (   name,
  ... 
)     WG14_RESULT_PREFIX(result_##name##_make_failure)(__VA_ARGS__)

Make a failed named Result previously declared.

Definition at line 212 of file result.h.

◆ WG14_RESULT_MAKE_SUCCESS

#define WG14_RESULT_MAKE_SUCCESS (   name,
  ... 
)     WG14_RESULT_PREFIX(result_##name##_make_success)(__VA_ARGS__)

Make a successful named Result previously declared.

Definition at line 209 of file result.h.

Typedef Documentation

◆ result_with_void

A Result for type void.

Enumeration Type Documentation

◆ result_status_flags

Enumerator
result_status_flag_none 
result_status_flag_have_value 
result_status_flag_have_error 
result_status_flag_have_exception 
result_status_flag_have_error_exception 
result_status_flag_have_lost_consistency 
result_status_flag_have_value_lost_consistency 
result_status_flag_have_error_lost_consistency 
result_status_flag_have_exception_lost_consistency 
result_status_flag_have_error_exception_lost_consistency 
result_status_flag_have_error_is_errno 
result_status_flag_have_error_error_is_errno 
result_status_flag_have_error_exception_error_is_errno 
result_status_flag_have_error_lost_consistency_error_is_errno 
result_status_flag_have_error_exception_lost_consistency_error_is_errno 
result_status_flag_have_moved_from 
result_status_flag_have_value_moved_from 
result_status_flag_have_error_moved_from 
result_status_flag_have_exception_moved_from 
result_status_flag_have_error_exception_moved_from 
result_status_flag_have_value_lost_consistency_moved_from 
result_status_flag_have_error_lost_consistency_moved_from 
result_status_flag_have_exception_lost_consistency_moved_from 
result_status_flag_have_error_exception_lost_consistency_moved_from 
result_status_flag_have_error_is_errno_moved_from 
result_status_flag_have_error_error_is_errno_moved_from 
result_status_flag_have_error_exception_error_is_errno_moved_from 
result_status_flag_have_error_lost_consistency_error_is_errno_moved_from 
result_status_flag_have_error_exception_lost_consistency_error_is_errno_moved_from 

Definition at line 37 of file result.h.