21#ifndef WG14_RESULT_CONFIG_H
22#define WG14_RESULT_CONFIG_H
24#if WG14_RESULT_ENABLE_HEADER_ONLY || WG14_RESULT_SOURCE
25#if defined(__cplusplus)
26#if __cplusplus < 202000L && !_HAS_CXX20
29#if __cplusplus < 202000L && !_HAS_CXX20
31"If being compiled as C++, the source code requires a minimum of a C++ 20 compiler for decent C11 support."
33#elif __STDC_VERSION__ < 201100L
35"The source code requires a minimum of a C11 compiler for atomics support."
39#ifndef WG14_RESULT_PREFIX
40#define WG14_RESULT_PREFIX(x) x
43#ifndef WG14_RESULT_NULLPTR
44#if __STDC_VERSION__ >= 202300L
45#define WG14_RESULT_NULLPTR nullptr
47#define WG14_RESULT_NULLPTR NULL
51#ifndef WG14_RESULT_CONSTEXPR
52#if __STDC_VERSION__ >= 202300L && (!defined(__clang__) || __clang_major >= 19)
53#define WG14_RESULT_CONSTEXPR constexpr
55#define WG14_RESULT_CONSTEXPR
59#ifndef WG14_RESULT_INLINE
60#if __STDC_VERSION__ >= 201100L
61#define WG14_RESULT_INLINE static inline
63#define WG14_RESULT_INLINE static
67#ifndef WG14_RESULT_TYPEOF
68#if __STDC_VERSION__ >= 202300L
69#define WG14_RESULT_TYPEOF(...) typeof(__VA_ARGS__)
71#define WG14_RESULT_TYPEOF(...) __typeof__(__VA_ARGS__)
75#ifndef WG14_RESULT_TYPEOF_UNQUAL
76#if __STDC_VERSION__ >= 202300L
77#define WG14_RESULT_TYPEOF_UNQUAL(...) typeof_unqual(__VA_ARGS__)
78#elif(defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 14) || \
79(defined(__clang__) && __clang_major__ < 19)
81#define WG14_RESULT_TYPEOF_UNQUAL(...) __typeof__(__VA_ARGS__)
83#define WG14_RESULT_TYPEOF_UNQUAL(...) __typeof_unqual__(__VA_ARGS__)
87#ifndef WG14_RESULT_CONSTEXPR_OR_CONST
88#if __STDC_VERSION__ >= 202300L && (!defined(__clang__) || __clang_major >= 19)
89#define WG14_RESULT_CONSTEXPR_OR_CONST constexpr
91#define WG14_RESULT_CONSTEXPR_OR_CONST const
95#ifndef WG14_RESULT_DEFAULT_VISIBILITY
97#define WG14_RESULT_DEFAULT_VISIBILITY
99#define WG14_RESULT_DEFAULT_VISIBILITY __attribute__((visibility("default")))
103#ifndef WG14_RESULT_EXTERN
104#if WG14_RESULT_SOURCE
106#define WG14_RESULT_EXTERN extern __declspec(dllexport)
108#define WG14_RESULT_EXTERN extern __attribute__((visibility("default")))
110#elif WG14_RESULT_ENABLE_HEADER_ONLY
111#define WG14_RESULT_EXTERN extern inline
113#define WG14_RESULT_EXTERN extern
117#ifndef WG14_RESULT_SINGLETON
118#if defined(__GNUC__) || defined(__clang__)
119#define WG14_RESULT_SINGLETON __attribute__((const))
121#define WG14_RESULT_SINGLETON
125#ifndef WG14_RESULT_STATIC_ASSERT_WITHIN_EXPR
126#define WG14_RESULT_STATIC_ASSERT_WITHIN_EXPR(pred, msg, ...) \
127 ((__VA_ARGS__) + 0 * sizeof(struct { \
128 _Static_assert((pred), msg); \
134#ifndef WG14_RESULT_STDERR_PRINTF
136#define WG14_RESULT_STDERR_PRINTF(...) fprintf(stderr, __VA_ARGS__)
139#ifndef WG14_RESULT_ABORTF
145__attribute__((noreturn))
147WG14_RESULT_PREFIX(abortf_impl)(
const char *msg, ...)
159#if defined(_MSC_VER) && !defined(__clang__)
160#define WG14_RESULT_ABORTF(X, ...) \
161 WG14_RESULT_PREFIX(abortf_impl)("FATAL: " X "\n", ##__VA_ARGS__)
162#elif __STDC_VERSION__ >= 202300L && !defined(__clang__)
163#define WG14_RESULT_ABORTF(X, ...) \
164 WG14_RESULT_PREFIX(abortf_impl)("FATAL: " X "\n" __VA_OPT(, ) __VA_ARGS__)
166#define WG14_RESULT_ABORTF_HAS_COMMA(...) \
167 WG14_RESULT_ABORTF_HAS_COMMA_16__(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
169#define WG14_RESULT_ABORTF_HAS_COMMA_16__( \
170_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, ...) \
172#define WG14_RESULT_ABORTF_CAT_(X, Y) X##Y
173#define WG14_RESULT_ABORTF_CAT(X, Y) WG14_RESULT_ABORTF_CAT_(X, Y)
174#define WG14_RESULT_ABORTF_INVOKE0(X) \
175 WG14_RESULT_PREFIX(abortf_impl)("FATAL: " X "\n")
176#define WG14_RESULT_ABORTF_INVOKE1(X, ...) \
177 WG14_RESULT_PREFIX(abortf_impl)("FATAL: " X "\n", __VA_ARGS__)
179#define WG14_RESULT_ABORTF(...) \
180 WG14_RESULT_ABORTF_CAT(WG14_RESULT_ABORTF_INVOKE, \
181 WG14_RESULT_ABORTF_HAS_COMMA(__VA_ARGS__)) \
vfprintf(stderr, msg, args)
#define WG14_RESULT_INLINE
static unsigned va_start(args, msg)