From 5bf34fbf997e5f4f3551cbe8d335964a046c27f4 Mon Sep 17 00:00:00 2001 From: "Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com)" Date: Wed, 17 Jul 2024 17:54:05 +0100 Subject: [PATCH] Fixes to previous commits as found the code didn't link under optimisation. --- include/outcome/detail/revision.hpp | 6 +- include/outcome/experimental/result.h | 66 ++++++++++--- single-header/outcome-basic.hpp | 132 ++++++++++++++++--------- single-header/outcome-experimental.hpp | 132 ++++++++++++++++--------- single-header/outcome.hpp | 132 ++++++++++++++++--------- 5 files changed, 309 insertions(+), 159 deletions(-) diff --git a/include/outcome/detail/revision.hpp b/include/outcome/detail/revision.hpp index 79107be4cc..f2bff875d2 100644 --- a/include/outcome/detail/revision.hpp +++ b/include/outcome/detail/revision.hpp @@ -22,6 +22,6 @@ Distributed under the Boost Software License, Version 1.0. */ // Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time -#define OUTCOME_PREVIOUS_COMMIT_REF 10eb45ca7d11a35df14e0fa89939a3e3185c0aa9 -#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-16 20:39:50 +00:00" -#define OUTCOME_PREVIOUS_COMMIT_UNIQUE 10eb45ca +#define OUTCOME_PREVIOUS_COMMIT_REF 6279affbf2fee17dbe2a564165b8815409565b10 +#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-17 14:25:30 +00:00" +#define OUTCOME_PREVIOUS_COMMIT_UNIQUE 6279affb diff --git a/include/outcome/experimental/result.h b/include/outcome/experimental/result.h index b9d9b5e6d9..be8567d360 100644 --- a/include/outcome/experimental/result.h +++ b/include/outcome/experimental/result.h @@ -36,6 +36,16 @@ Distributed under the Boost Software License, Version 1.0. #define OUTCOME_C_INLINE #endif +#ifndef OUTCOME_C_NODISCARD +#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 202000L +#define OUTCOME_C_NODISCARD [[nodiscard]] +#elif defined(__GNUC__) || defined(__clang__) +#define OUTCOME_C_NODISCARD __attribute__((warn_unused_result)) +#else +#define OUTCOME_C_NODISCARD +#endif +#endif + #include "../outcome_gdb.h" #ifdef __cplusplus @@ -105,7 +115,7 @@ extern "C" pun.c = v; \ return std::move(pun.cpp); \ } \ - inline cxx_result_status_code_##ident to_##ident(OUTCOME_V2_NAMESPACE::experimental::status_result v) \ + inline OUTCOME_C_NODISCARD cxx_result_status_code_##ident to_##ident(OUTCOME_V2_NAMESPACE::experimental::status_result v) \ { \ union type_punner_t \ { \ @@ -132,20 +142,20 @@ extern "C" unsigned flags; \ S error; \ }; \ - static OUTCOME_C_INLINE struct cxx_result_status_code_##ident outcome_make_result_##ident##_success(R value) \ + static OUTCOME_C_INLINE OUTCOME_C_NODISCARD struct cxx_result_status_code_##ident outcome_make_result_##ident##_success(R value) \ { \ struct cxx_result_status_code_##ident ret; \ outcome_make_result_status_code_success((void *) &ret, sizeof(ret), offsetof(struct cxx_result_status_code_##ident, flags), (const void *) &value, \ sizeof(value)); \ return ret; \ } \ - static OUTCOME_C_INLINE struct cxx_result_status_code_##ident outcome_make_result_##ident##_failure_posix(int errcode) \ + static OUTCOME_C_INLINE OUTCOME_C_NODISCARD struct cxx_result_status_code_##ident outcome_make_result_##ident##_failure_posix(int errcode) \ { \ struct cxx_result_status_code_##ident ret; \ outcome_make_result_status_code_failure_posix((void *) &ret, sizeof(ret), offsetof(struct cxx_result_status_code_##ident, flags), errcode); \ return ret; \ } \ - static OUTCOME_C_INLINE struct cxx_result_status_code_##ident outcome_make_result_##ident##_failure_system(intptr_t errcode) \ + static OUTCOME_C_INLINE OUTCOME_C_NODISCARD struct cxx_result_status_code_##ident outcome_make_result_##ident##_failure_system(intptr_t errcode) \ { \ struct cxx_result_status_code_##ident ret; \ outcome_make_result_status_code_failure_system((void *) &ret, sizeof(ret), offsetof(struct cxx_result_status_code_##ident, flags), errcode); \ @@ -223,7 +233,7 @@ extern "C" #ifndef __cplusplus // Declares the function in C, needs to occur at least once in a C++ source file to get implemented #define CXX_DECLARE_RESULT_SYSTEM_FROM_ENUM(ident, enum_name, uuid, ...) \ - extern struct cxx_result_status_code_system_##ident outcome_make_result_##ident##_failure_system_enum_##enum_name(enum enum_name v); + extern OUTCOME_C_NODISCARD struct cxx_result_status_code_system_##ident outcome_make_result_##ident##_failure_system_enum_##enum_name(enum enum_name v); #else } @@ -241,8 +251,25 @@ extern "C" #include #include +#ifndef OUTCOME_C_WEAK +#ifdef _MSC_VER +#define OUTCOME_C_WEAK inline +#else +#define OUTCOME_C_WEAK __attribute__((weak)) +#endif +#endif + +#ifndef OUTCOME_C_MSVC_FORCE_EMIT +#ifdef _MSC_VER +#define OUTCOME_C_MSVC_FORCE_EMIT(x) extern "C" __declspec(selectany) void *x##_emit = x; +#else +#define OUTCOME_C_MSVC_FORCE_EMIT(x) +#endif +#endif + + // You need to include this C header in at least one C++ source file to have these C helper functions be implemented -extern "C" inline void outcome_make_result_status_code_success(void *out, size_t bytes, size_t offset, const void *toset, size_t tosetbytes) +extern "C" OUTCOME_C_WEAK void outcome_make_result_status_code_success(void *out, size_t bytes, size_t offset, const void *toset, size_t tosetbytes) { union type_punner_t { @@ -267,8 +294,9 @@ extern "C" inline void outcome_make_result_status_code_success(void *out, size_t memcpy(out, toset, tosetbytes); memcpy((void *) ((char *) out + offset), (const void *) ((const char *) &pun.c + punoffset), tocopy); } +OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_status_code_success) -extern "C" inline void outcome_make_result_status_code_failure_posix(void *out, size_t bytes, size_t offset, int errcode) +extern "C" OUTCOME_C_WEAK void outcome_make_result_status_code_failure_posix(void *out, size_t bytes, size_t offset, int errcode) { using value_type = OUTCOME_V2_NAMESPACE::experimental::posix_code::value_type; union type_punner_t @@ -294,8 +322,9 @@ extern "C" inline void outcome_make_result_status_code_failure_posix(void *out, memcpy(out, (void *) &pun.c, sizeof(value_type)); memcpy((void *) ((char *) out + offset), (const void *) ((const char *) &pun.c + punoffset), tocopy); } +OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_status_code_failure_posix) -extern "C" inline void outcome_make_result_status_code_failure_system(void *out, size_t bytes, size_t offset, intptr_t errcode) +extern "C" OUTCOME_C_WEAK void outcome_make_result_status_code_failure_system(void *out, size_t bytes, size_t offset, intptr_t errcode) { using value_type = OUTCOME_V2_NAMESPACE::experimental::system_code::value_type; union type_punner_t @@ -315,9 +344,9 @@ extern "C" inline void outcome_make_result_status_code_failure_system(void *out, ~type_punner_t() {} } pun{ #ifdef _WIN32 - OUTCOME_V2_NAMESPACE::experimental::win32_code(errcode) + OUTCOME_V2_NAMESPACE::experimental::win32_code((OUTCOME_V2_NAMESPACE::experimental::win32::DWORD) errcode) #else - OUTCOME_V2_NAMESPACE::experimental::posix_code(errcode) + OUTCOME_V2_NAMESPACE::experimental::posix_code((int) errcode) #endif }; static_assert(sizeof(pun.cpp) == sizeof(pun.c), ""); @@ -327,27 +356,31 @@ extern "C" inline void outcome_make_result_status_code_failure_system(void *out, memcpy(out, (void *) &pun.c, sizeof(value_type)); memcpy((void *) ((char *) out + offset), (const void *) ((const char *) &pun.c + punoffset), tocopy); } +OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_status_code_failure_system) -extern "C" inline int outcome_status_code_equal(const void *_a, const void *_b) +extern "C" OUTCOME_C_WEAK int outcome_status_code_equal(const void *_a, const void *_b) { const auto *a = (const SYSTEM_ERROR2_NAMESPACE::system_code *) _a; const auto *b = (const SYSTEM_ERROR2_NAMESPACE::system_code *) _b; return *a == *b; } +OUTCOME_C_MSVC_FORCE_EMIT(outcome_status_code_equal) -extern "C" inline int outcome_status_code_equal_generic(const void *_a, int errcode) +extern "C" OUTCOME_C_WEAK int outcome_status_code_equal_generic(const void *_a, int errcode) { const auto *a = (const SYSTEM_ERROR2_NAMESPACE::system_code *) _a; return *a == (SYSTEM_ERROR2_NAMESPACE::errc) errcode; } +OUTCOME_C_MSVC_FORCE_EMIT(outcome_status_code_equal_generic) -extern "C" inline const char *outcome_status_code_message(const void *_a) +extern "C" OUTCOME_C_WEAK const char *outcome_status_code_message(const void *_a) { static thread_local SYSTEM_ERROR2_NAMESPACE::system_code::string_ref msg((const char *) nullptr, 0); const auto *a = (const SYSTEM_ERROR2_NAMESPACE::system_code *) _a; msg = a->message(); return msg.c_str(); } +OUTCOME_C_MSVC_FORCE_EMIT(outcome_status_code_message) OUTCOME_V2_NAMESPACE_BEGIN namespace experimental @@ -402,10 +435,13 @@ OUTCOME_V2_NAMESPACE_END } \ }; \ SYSTEM_ERROR2_NAMESPACE_END \ - extern "C" inline struct cxx_result_status_code_system_##ident outcome_make_result_##ident##_failure_system_enum_##enum_name(enum enum_name v) \ + extern "C" OUTCOME_C_WEAK OUTCOME_C_NODISCARD struct cxx_result_status_code_system_##ident outcome_make_result_##ident##_failure_system_enum_##enum_name( \ + enum enum_name v) \ { \ return OUTCOME_V2_NAMESPACE::experimental::detail::outcome_make_result_failure_system_enum(v); \ - } + } \ + OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_##ident##_failure_system_enum_##enum_name) + #endif diff --git a/single-header/outcome-basic.hpp b/single-header/outcome-basic.hpp index a31f547567..1ba5f688c7 100644 --- a/single-header/outcome-basic.hpp +++ b/single-header/outcome-basic.hpp @@ -1019,9 +1019,9 @@ Distributed under the Boost Software License, Version 1.0. http://www.boost.org/LICENSE_1_0.txt) */ // Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time -#define OUTCOME_PREVIOUS_COMMIT_REF 5bcd0f32f28659a0eab62f1d643d878c2220788d -#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-15 17:46:44 +00:00" -#define OUTCOME_PREVIOUS_COMMIT_UNIQUE 5bcd0f32 +#define OUTCOME_PREVIOUS_COMMIT_REF 6279affbf2fee17dbe2a564165b8815409565b10 +#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-17 14:25:30 +00:00" +#define OUTCOME_PREVIOUS_COMMIT_UNIQUE 6279affb #define OUTCOME_V2 (QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2)) #ifdef _DEBUG #define OUTCOME_V2_CXX_MODULE_NAME QUICKCPPLIB_BIND_NAMESPACE((QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2d))) @@ -6334,6 +6334,88 @@ Distributed under the Boost Software License, Version 1.0. */ #ifndef OUTCOME_TRY_HPP #define OUTCOME_TRY_HPP +/* Try operation macros +(C) 2017-2024 Niall Douglas (20 commits) +File Created: July 2017 + + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License in the accompanying file +Licence.txt or at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + +Distributed under the Boost Software License, Version 1.0. + (See accompanying file Licence.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +#ifndef OUTCOME_TRY_H +#define OUTCOME_TRY_H +#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wparentheses" +#endif +#define OUTCOME_TRY_GLUE2(x, y) x##y +#define OUTCOME_TRY_GLUE(x, y) OUTCOME_TRY_GLUE2(x, y) +#define OUTCOME_TRY_UNIQUE_NAME OUTCOME_TRY_GLUE(_outcome_try_unique_name_temporary, __COUNTER__) +#define OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count +#define OUTCOME_TRY_EXPAND_ARGS(args) OUTCOME_TRY_RETURN_ARG_COUNT args +#define OUTCOME_TRY_COUNT_ARGS_MAX8(...) OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) +#define OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count +#define OUTCOME_TRY_OVERLOAD_MACRO1(name, count) OUTCOME_TRY_OVERLOAD_MACRO2(name, count) +#define OUTCOME_TRY_OVERLOAD_MACRO(name, count) OUTCOME_TRY_OVERLOAD_MACRO1(name, count) +#define OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y +#define OUTCOME_TRY_CALL_OVERLOAD(name, ...) OUTCOME_TRY_OVERLOAD_GLUE(OUTCOME_TRY_OVERLOAD_MACRO(name, OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) +#define _OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count +#define _OUTCOME_TRY_EXPAND_ARGS(args) _OUTCOME_TRY_RETURN_ARG_COUNT args +#define _OUTCOME_TRY_COUNT_ARGS_MAX8(...) _OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) +#define _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count +#define _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) +#define _OUTCOME_TRY_OVERLOAD_MACRO(name, count) _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) +#define _OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y +#define _OUTCOME_TRY_CALL_OVERLOAD(name, ...) _OUTCOME_TRY_OVERLOAD_GLUE(_OUTCOME_TRY_OVERLOAD_MACRO(name, _OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) +#if !defined(OUTCOME_TRY_LIKELY_IF) && defined(__has_cpp_attribute) +#if __has_cpp_attribute(likely) +#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) [[likely]] +#endif +#endif +#ifndef OUTCOME_TRY_LIKELY_IF +#if defined(__clang__) || defined(__GNUC__) +#define OUTCOME_TRY_LIKELY_IF(...) if(__builtin_expect(!!(__VA_ARGS__), 1)) +#else +#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) +#endif +#endif +#ifdef __cplusplus +#define OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(...) auto +#else +#define OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(...) __typeof__(__VA_ARGS__) +#endif +#define OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK(...) __VA_ARGS__ +#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(__VA_ARGS__) unique = (__VA_ARGS__) +#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(x) x +#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE(unique, x, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, __VA_ARGS__)) +#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, x, y, ...) x unique = (__VA_ARGS__) +#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(x) x +#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, __VA_ARGS__)) +#define OUTCOME_TRYV2_UNIQUE_STORAGE1(...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE +#define OUTCOME_TRYV2_UNIQUE_STORAGE2(...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED +#define OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, ...) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRYV2_UNIQUE_STORAGE, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec) (unique, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, __VA_ARGS__) +#define OUTCOME_TRY2_VAR_SECOND2(x, var) var +#define OUTCOME_TRY2_VAR_SECOND3(x, y, ...) x y +#define OUTCOME_TRY2_VAR(spec) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY2_VAR_SECOND, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, spec) +#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8 +#pragma GCC diagnostic pop +#endif +#endif OUTCOME_V2_NAMESPACE_BEGIN namespace detail { @@ -6469,53 +6551,9 @@ OUTCOME_V2_NAMESPACE_END #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wparentheses" #endif -#define OUTCOME_TRY_GLUE2(x, y) x##y -#define OUTCOME_TRY_GLUE(x, y) OUTCOME_TRY_GLUE2(x, y) -#define OUTCOME_TRY_UNIQUE_NAME OUTCOME_TRY_GLUE(_outcome_try_unique_name_temporary, __COUNTER__) -#define OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count -#define OUTCOME_TRY_EXPAND_ARGS(args) OUTCOME_TRY_RETURN_ARG_COUNT args -#define OUTCOME_TRY_COUNT_ARGS_MAX8(...) OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) -#define OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count -#define OUTCOME_TRY_OVERLOAD_MACRO1(name, count) OUTCOME_TRY_OVERLOAD_MACRO2(name, count) -#define OUTCOME_TRY_OVERLOAD_MACRO(name, count) OUTCOME_TRY_OVERLOAD_MACRO1(name, count) -#define OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y -#define OUTCOME_TRY_CALL_OVERLOAD(name, ...) OUTCOME_TRY_OVERLOAD_GLUE(OUTCOME_TRY_OVERLOAD_MACRO(name, OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) -#define _OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count -#define _OUTCOME_TRY_EXPAND_ARGS(args) _OUTCOME_TRY_RETURN_ARG_COUNT args -#define _OUTCOME_TRY_COUNT_ARGS_MAX8(...) _OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) -#define _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count -#define _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) -#define _OUTCOME_TRY_OVERLOAD_MACRO(name, count) _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) -#define _OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y -#define _OUTCOME_TRY_CALL_OVERLOAD(name, ...) _OUTCOME_TRY_OVERLOAD_GLUE(_OUTCOME_TRY_OVERLOAD_MACRO(name, _OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) -#if !defined(OUTCOME_TRY_LIKELY_IF) && defined(__has_cpp_attribute) -#if __has_cpp_attribute(likely) -#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) [[likely]] -#endif -#endif -#ifndef OUTCOME_TRY_LIKELY_IF -#if defined(__clang__) || defined(__GNUC__) -#define OUTCOME_TRY_LIKELY_IF(...) if(__builtin_expect(!!(__VA_ARGS__), true)) -#else -#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) -#endif -#endif -#define OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK(...) __VA_ARGS__ -#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, ...) auto unique = (__VA_ARGS__) -#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(x) x -#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE(unique, x, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, __VA_ARGS__)) -#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, x, y, ...) x unique = (__VA_ARGS__) -#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(x) x -#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, __VA_ARGS__)) -#define OUTCOME_TRYV2_UNIQUE_STORAGE1(...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE -#define OUTCOME_TRYV2_UNIQUE_STORAGE2(...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED -#define OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, ...) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRYV2_UNIQUE_STORAGE, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec) (unique, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, __VA_ARGS__) // Use if(!expr); else as some compilers assume else clauses are always unlikely #define OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, spec, ...) OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); OUTCOME_TRY_LIKELY_IF(::OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)); else { /* works around ICE in GCC's coroutines implementation */ auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast(unique))); retstmt unique##_f; } #define OUTCOME_TRYV3_FAILURE_LIKELY(unique, retstmt, spec, ...) OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); OUTCOME_TRY_LIKELY_IF(!OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)) { /* works around ICE in GCC's coroutines implementation */ auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast(unique))); retstmt unique##_f; } -#define OUTCOME_TRY2_VAR_SECOND2(x, var) var -#define OUTCOME_TRY2_VAR_SECOND3(x, y, ...) x y -#define OUTCOME_TRY2_VAR(spec) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY2_VAR_SECOND, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, spec) #define OUTCOME_TRY2_SUCCESS_LIKELY(unique, retstmt, var, ...) OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, var, __VA_ARGS__); OUTCOME_TRY2_VAR(var) = ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast(unique)) #define OUTCOME_TRY2_FAILURE_LIKELY(unique, retstmt, var, ...) OUTCOME_TRYV3_FAILURE_LIKELY(unique, retstmt, var, __VA_ARGS__); OUTCOME_TRY2_VAR(var) = ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast(unique)) /*! AWAITING HUGO JSON CONVERSION TOOL diff --git a/single-header/outcome-experimental.hpp b/single-header/outcome-experimental.hpp index 689b63b698..3d890fbb3e 100644 --- a/single-header/outcome-experimental.hpp +++ b/single-header/outcome-experimental.hpp @@ -1044,9 +1044,9 @@ Distributed under the Boost Software License, Version 1.0. http://www.boost.org/LICENSE_1_0.txt) */ // Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time -#define OUTCOME_PREVIOUS_COMMIT_REF 5bcd0f32f28659a0eab62f1d643d878c2220788d -#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-15 17:46:44 +00:00" -#define OUTCOME_PREVIOUS_COMMIT_UNIQUE 5bcd0f32 +#define OUTCOME_PREVIOUS_COMMIT_REF 6279affbf2fee17dbe2a564165b8815409565b10 +#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-17 14:25:30 +00:00" +#define OUTCOME_PREVIOUS_COMMIT_UNIQUE 6279affb #define OUTCOME_V2 (QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2)) #ifdef _DEBUG #define OUTCOME_V2_CXX_MODULE_NAME QUICKCPPLIB_BIND_NAMESPACE((QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2d))) @@ -11645,6 +11645,88 @@ Distributed under the Boost Software License, Version 1.0. */ #ifndef OUTCOME_TRY_HPP #define OUTCOME_TRY_HPP +/* Try operation macros +(C) 2017-2024 Niall Douglas (20 commits) +File Created: July 2017 + + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License in the accompanying file +Licence.txt or at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + +Distributed under the Boost Software License, Version 1.0. + (See accompanying file Licence.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +#ifndef OUTCOME_TRY_H +#define OUTCOME_TRY_H +#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wparentheses" +#endif +#define OUTCOME_TRY_GLUE2(x, y) x##y +#define OUTCOME_TRY_GLUE(x, y) OUTCOME_TRY_GLUE2(x, y) +#define OUTCOME_TRY_UNIQUE_NAME OUTCOME_TRY_GLUE(_outcome_try_unique_name_temporary, __COUNTER__) +#define OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count +#define OUTCOME_TRY_EXPAND_ARGS(args) OUTCOME_TRY_RETURN_ARG_COUNT args +#define OUTCOME_TRY_COUNT_ARGS_MAX8(...) OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) +#define OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count +#define OUTCOME_TRY_OVERLOAD_MACRO1(name, count) OUTCOME_TRY_OVERLOAD_MACRO2(name, count) +#define OUTCOME_TRY_OVERLOAD_MACRO(name, count) OUTCOME_TRY_OVERLOAD_MACRO1(name, count) +#define OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y +#define OUTCOME_TRY_CALL_OVERLOAD(name, ...) OUTCOME_TRY_OVERLOAD_GLUE(OUTCOME_TRY_OVERLOAD_MACRO(name, OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) +#define _OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count +#define _OUTCOME_TRY_EXPAND_ARGS(args) _OUTCOME_TRY_RETURN_ARG_COUNT args +#define _OUTCOME_TRY_COUNT_ARGS_MAX8(...) _OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) +#define _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count +#define _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) +#define _OUTCOME_TRY_OVERLOAD_MACRO(name, count) _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) +#define _OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y +#define _OUTCOME_TRY_CALL_OVERLOAD(name, ...) _OUTCOME_TRY_OVERLOAD_GLUE(_OUTCOME_TRY_OVERLOAD_MACRO(name, _OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) +#if !defined(OUTCOME_TRY_LIKELY_IF) && defined(__has_cpp_attribute) +#if __has_cpp_attribute(likely) +#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) [[likely]] +#endif +#endif +#ifndef OUTCOME_TRY_LIKELY_IF +#if defined(__clang__) || defined(__GNUC__) +#define OUTCOME_TRY_LIKELY_IF(...) if(__builtin_expect(!!(__VA_ARGS__), 1)) +#else +#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) +#endif +#endif +#ifdef __cplusplus +#define OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(...) auto +#else +#define OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(...) __typeof__(__VA_ARGS__) +#endif +#define OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK(...) __VA_ARGS__ +#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(__VA_ARGS__) unique = (__VA_ARGS__) +#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(x) x +#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE(unique, x, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, __VA_ARGS__)) +#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, x, y, ...) x unique = (__VA_ARGS__) +#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(x) x +#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, __VA_ARGS__)) +#define OUTCOME_TRYV2_UNIQUE_STORAGE1(...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE +#define OUTCOME_TRYV2_UNIQUE_STORAGE2(...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED +#define OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, ...) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRYV2_UNIQUE_STORAGE, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec) (unique, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, __VA_ARGS__) +#define OUTCOME_TRY2_VAR_SECOND2(x, var) var +#define OUTCOME_TRY2_VAR_SECOND3(x, y, ...) x y +#define OUTCOME_TRY2_VAR(spec) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY2_VAR_SECOND, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, spec) +#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8 +#pragma GCC diagnostic pop +#endif +#endif OUTCOME_V2_NAMESPACE_BEGIN namespace detail { @@ -11780,53 +11862,9 @@ OUTCOME_V2_NAMESPACE_END #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wparentheses" #endif -#define OUTCOME_TRY_GLUE2(x, y) x##y -#define OUTCOME_TRY_GLUE(x, y) OUTCOME_TRY_GLUE2(x, y) -#define OUTCOME_TRY_UNIQUE_NAME OUTCOME_TRY_GLUE(_outcome_try_unique_name_temporary, __COUNTER__) -#define OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count -#define OUTCOME_TRY_EXPAND_ARGS(args) OUTCOME_TRY_RETURN_ARG_COUNT args -#define OUTCOME_TRY_COUNT_ARGS_MAX8(...) OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) -#define OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count -#define OUTCOME_TRY_OVERLOAD_MACRO1(name, count) OUTCOME_TRY_OVERLOAD_MACRO2(name, count) -#define OUTCOME_TRY_OVERLOAD_MACRO(name, count) OUTCOME_TRY_OVERLOAD_MACRO1(name, count) -#define OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y -#define OUTCOME_TRY_CALL_OVERLOAD(name, ...) OUTCOME_TRY_OVERLOAD_GLUE(OUTCOME_TRY_OVERLOAD_MACRO(name, OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) -#define _OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count -#define _OUTCOME_TRY_EXPAND_ARGS(args) _OUTCOME_TRY_RETURN_ARG_COUNT args -#define _OUTCOME_TRY_COUNT_ARGS_MAX8(...) _OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) -#define _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count -#define _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) -#define _OUTCOME_TRY_OVERLOAD_MACRO(name, count) _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) -#define _OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y -#define _OUTCOME_TRY_CALL_OVERLOAD(name, ...) _OUTCOME_TRY_OVERLOAD_GLUE(_OUTCOME_TRY_OVERLOAD_MACRO(name, _OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) -#if !defined(OUTCOME_TRY_LIKELY_IF) && defined(__has_cpp_attribute) -#if __has_cpp_attribute(likely) -#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) [[likely]] -#endif -#endif -#ifndef OUTCOME_TRY_LIKELY_IF -#if defined(__clang__) || defined(__GNUC__) -#define OUTCOME_TRY_LIKELY_IF(...) if(__builtin_expect(!!(__VA_ARGS__), true)) -#else -#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) -#endif -#endif -#define OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK(...) __VA_ARGS__ -#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, ...) auto unique = (__VA_ARGS__) -#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(x) x -#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE(unique, x, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, __VA_ARGS__)) -#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, x, y, ...) x unique = (__VA_ARGS__) -#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(x) x -#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, __VA_ARGS__)) -#define OUTCOME_TRYV2_UNIQUE_STORAGE1(...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE -#define OUTCOME_TRYV2_UNIQUE_STORAGE2(...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED -#define OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, ...) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRYV2_UNIQUE_STORAGE, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec) (unique, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, __VA_ARGS__) // Use if(!expr); else as some compilers assume else clauses are always unlikely #define OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, spec, ...) OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); OUTCOME_TRY_LIKELY_IF(::OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)); else { /* works around ICE in GCC's coroutines implementation */ auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast(unique))); retstmt unique##_f; } #define OUTCOME_TRYV3_FAILURE_LIKELY(unique, retstmt, spec, ...) OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); OUTCOME_TRY_LIKELY_IF(!OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)) { /* works around ICE in GCC's coroutines implementation */ auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast(unique))); retstmt unique##_f; } -#define OUTCOME_TRY2_VAR_SECOND2(x, var) var -#define OUTCOME_TRY2_VAR_SECOND3(x, y, ...) x y -#define OUTCOME_TRY2_VAR(spec) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY2_VAR_SECOND, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, spec) #define OUTCOME_TRY2_SUCCESS_LIKELY(unique, retstmt, var, ...) OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, var, __VA_ARGS__); OUTCOME_TRY2_VAR(var) = ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast(unique)) #define OUTCOME_TRY2_FAILURE_LIKELY(unique, retstmt, var, ...) OUTCOME_TRYV3_FAILURE_LIKELY(unique, retstmt, var, __VA_ARGS__); OUTCOME_TRY2_VAR(var) = ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast(unique)) /*! AWAITING HUGO JSON CONVERSION TOOL diff --git a/single-header/outcome.hpp b/single-header/outcome.hpp index 8caece5e9a..6f14141dab 100644 --- a/single-header/outcome.hpp +++ b/single-header/outcome.hpp @@ -1043,9 +1043,9 @@ Distributed under the Boost Software License, Version 1.0. http://www.boost.org/LICENSE_1_0.txt) */ // Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time -#define OUTCOME_PREVIOUS_COMMIT_REF 5bcd0f32f28659a0eab62f1d643d878c2220788d -#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-15 17:46:44 +00:00" -#define OUTCOME_PREVIOUS_COMMIT_UNIQUE 5bcd0f32 +#define OUTCOME_PREVIOUS_COMMIT_REF 6279affbf2fee17dbe2a564165b8815409565b10 +#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-17 14:25:30 +00:00" +#define OUTCOME_PREVIOUS_COMMIT_UNIQUE 6279affb #define OUTCOME_V2 (QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2)) #ifdef _DEBUG #define OUTCOME_V2_CXX_MODULE_NAME QUICKCPPLIB_BIND_NAMESPACE((QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2d))) @@ -8297,6 +8297,88 @@ Distributed under the Boost Software License, Version 1.0. */ #ifndef OUTCOME_TRY_HPP #define OUTCOME_TRY_HPP +/* Try operation macros +(C) 2017-2024 Niall Douglas (20 commits) +File Created: July 2017 + + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License in the accompanying file +Licence.txt or at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + +Distributed under the Boost Software License, Version 1.0. + (See accompanying file Licence.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +#ifndef OUTCOME_TRY_H +#define OUTCOME_TRY_H +#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wparentheses" +#endif +#define OUTCOME_TRY_GLUE2(x, y) x##y +#define OUTCOME_TRY_GLUE(x, y) OUTCOME_TRY_GLUE2(x, y) +#define OUTCOME_TRY_UNIQUE_NAME OUTCOME_TRY_GLUE(_outcome_try_unique_name_temporary, __COUNTER__) +#define OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count +#define OUTCOME_TRY_EXPAND_ARGS(args) OUTCOME_TRY_RETURN_ARG_COUNT args +#define OUTCOME_TRY_COUNT_ARGS_MAX8(...) OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) +#define OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count +#define OUTCOME_TRY_OVERLOAD_MACRO1(name, count) OUTCOME_TRY_OVERLOAD_MACRO2(name, count) +#define OUTCOME_TRY_OVERLOAD_MACRO(name, count) OUTCOME_TRY_OVERLOAD_MACRO1(name, count) +#define OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y +#define OUTCOME_TRY_CALL_OVERLOAD(name, ...) OUTCOME_TRY_OVERLOAD_GLUE(OUTCOME_TRY_OVERLOAD_MACRO(name, OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) +#define _OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count +#define _OUTCOME_TRY_EXPAND_ARGS(args) _OUTCOME_TRY_RETURN_ARG_COUNT args +#define _OUTCOME_TRY_COUNT_ARGS_MAX8(...) _OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) +#define _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count +#define _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) +#define _OUTCOME_TRY_OVERLOAD_MACRO(name, count) _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) +#define _OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y +#define _OUTCOME_TRY_CALL_OVERLOAD(name, ...) _OUTCOME_TRY_OVERLOAD_GLUE(_OUTCOME_TRY_OVERLOAD_MACRO(name, _OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) +#if !defined(OUTCOME_TRY_LIKELY_IF) && defined(__has_cpp_attribute) +#if __has_cpp_attribute(likely) +#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) [[likely]] +#endif +#endif +#ifndef OUTCOME_TRY_LIKELY_IF +#if defined(__clang__) || defined(__GNUC__) +#define OUTCOME_TRY_LIKELY_IF(...) if(__builtin_expect(!!(__VA_ARGS__), 1)) +#else +#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) +#endif +#endif +#ifdef __cplusplus +#define OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(...) auto +#else +#define OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(...) __typeof__(__VA_ARGS__) +#endif +#define OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK(...) __VA_ARGS__ +#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(__VA_ARGS__) unique = (__VA_ARGS__) +#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(x) x +#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE(unique, x, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, __VA_ARGS__)) +#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, x, y, ...) x unique = (__VA_ARGS__) +#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(x) x +#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, __VA_ARGS__)) +#define OUTCOME_TRYV2_UNIQUE_STORAGE1(...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE +#define OUTCOME_TRYV2_UNIQUE_STORAGE2(...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED +#define OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, ...) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRYV2_UNIQUE_STORAGE, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec) (unique, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, __VA_ARGS__) +#define OUTCOME_TRY2_VAR_SECOND2(x, var) var +#define OUTCOME_TRY2_VAR_SECOND3(x, y, ...) x y +#define OUTCOME_TRY2_VAR(spec) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY2_VAR_SECOND, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, spec) +#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8 +#pragma GCC diagnostic pop +#endif +#endif OUTCOME_V2_NAMESPACE_BEGIN namespace detail { @@ -8432,53 +8514,9 @@ OUTCOME_V2_NAMESPACE_END #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wparentheses" #endif -#define OUTCOME_TRY_GLUE2(x, y) x##y -#define OUTCOME_TRY_GLUE(x, y) OUTCOME_TRY_GLUE2(x, y) -#define OUTCOME_TRY_UNIQUE_NAME OUTCOME_TRY_GLUE(_outcome_try_unique_name_temporary, __COUNTER__) -#define OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count -#define OUTCOME_TRY_EXPAND_ARGS(args) OUTCOME_TRY_RETURN_ARG_COUNT args -#define OUTCOME_TRY_COUNT_ARGS_MAX8(...) OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) -#define OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count -#define OUTCOME_TRY_OVERLOAD_MACRO1(name, count) OUTCOME_TRY_OVERLOAD_MACRO2(name, count) -#define OUTCOME_TRY_OVERLOAD_MACRO(name, count) OUTCOME_TRY_OVERLOAD_MACRO1(name, count) -#define OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y -#define OUTCOME_TRY_CALL_OVERLOAD(name, ...) OUTCOME_TRY_OVERLOAD_GLUE(OUTCOME_TRY_OVERLOAD_MACRO(name, OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) -#define _OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count -#define _OUTCOME_TRY_EXPAND_ARGS(args) _OUTCOME_TRY_RETURN_ARG_COUNT args -#define _OUTCOME_TRY_COUNT_ARGS_MAX8(...) _OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) -#define _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count -#define _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) -#define _OUTCOME_TRY_OVERLOAD_MACRO(name, count) _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) -#define _OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y -#define _OUTCOME_TRY_CALL_OVERLOAD(name, ...) _OUTCOME_TRY_OVERLOAD_GLUE(_OUTCOME_TRY_OVERLOAD_MACRO(name, _OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) -#if !defined(OUTCOME_TRY_LIKELY_IF) && defined(__has_cpp_attribute) -#if __has_cpp_attribute(likely) -#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) [[likely]] -#endif -#endif -#ifndef OUTCOME_TRY_LIKELY_IF -#if defined(__clang__) || defined(__GNUC__) -#define OUTCOME_TRY_LIKELY_IF(...) if(__builtin_expect(!!(__VA_ARGS__), true)) -#else -#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) -#endif -#endif -#define OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK(...) __VA_ARGS__ -#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, ...) auto unique = (__VA_ARGS__) -#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(x) x -#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE(unique, x, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, __VA_ARGS__)) -#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, x, y, ...) x unique = (__VA_ARGS__) -#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(x) x -#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, __VA_ARGS__)) -#define OUTCOME_TRYV2_UNIQUE_STORAGE1(...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE -#define OUTCOME_TRYV2_UNIQUE_STORAGE2(...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED -#define OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, ...) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRYV2_UNIQUE_STORAGE, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec) (unique, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, __VA_ARGS__) // Use if(!expr); else as some compilers assume else clauses are always unlikely #define OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, spec, ...) OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); OUTCOME_TRY_LIKELY_IF(::OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)); else { /* works around ICE in GCC's coroutines implementation */ auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast(unique))); retstmt unique##_f; } #define OUTCOME_TRYV3_FAILURE_LIKELY(unique, retstmt, spec, ...) OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); OUTCOME_TRY_LIKELY_IF(!OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)) { /* works around ICE in GCC's coroutines implementation */ auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast(unique))); retstmt unique##_f; } -#define OUTCOME_TRY2_VAR_SECOND2(x, var) var -#define OUTCOME_TRY2_VAR_SECOND3(x, y, ...) x y -#define OUTCOME_TRY2_VAR(spec) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY2_VAR_SECOND, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, spec) #define OUTCOME_TRY2_SUCCESS_LIKELY(unique, retstmt, var, ...) OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, var, __VA_ARGS__); OUTCOME_TRY2_VAR(var) = ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast(unique)) #define OUTCOME_TRY2_FAILURE_LIKELY(unique, retstmt, var, ...) OUTCOME_TRYV3_FAILURE_LIKELY(unique, retstmt, var, __VA_ARGS__); OUTCOME_TRY2_VAR(var) = ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast(unique)) /*! AWAITING HUGO JSON CONVERSION TOOL