From 3519b5a457aaa4b5de355c55ce9570ffbaed1dad Mon Sep 17 00:00:00 2001 From: "Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com)" Date: Wed, 17 Jul 2024 15:16:25 +0100 Subject: [PATCH] Add missing docs for previous commit. --- .../experimental/c-api/from-c/system_code.md | 14 ++++++++++++++ include/outcome/detail/revision.hpp | 6 +++--- include/outcome/experimental/result.h | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/doc/src/content/experimental/c-api/from-c/system_code.md b/doc/src/content/experimental/c-api/from-c/system_code.md index 3efc5ae6bf..2d6dd67219 100644 --- a/doc/src/content/experimental/c-api/from-c/system_code.md +++ b/doc/src/content/experimental/c-api/from-c/system_code.md @@ -82,5 +82,19 @@ as per the quick_status_code_from_enum documentation. from a C enum. +The operations available to C++ are: + +
+
CXX_TO_RESULT_SYSTEM_CODE(ident, status_code<T>) +
Returns a previously declared C Result from its matching C++ status_code. +NOTE that the destructor of the C++ status code is NOT called. If this is important +to your status code, it is 100% on you to ensure that your C Result reenters a C++ +Result at the end of its lifetime. + +
to_result(any C Result) +
This is an overloaded C++ free function which returns the C++ status_code<T> +matching its input C Result. +
+ Using the above you can write C code using Outcome.Experimental's Result type quite effectively. Let's look at an example of use next. diff --git a/include/outcome/detail/revision.hpp b/include/outcome/detail/revision.hpp index e5fccf3619..79107be4cc 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 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 10eb45ca7d11a35df14e0fa89939a3e3185c0aa9 +#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-16 20:39:50 +00:00" +#define OUTCOME_PREVIOUS_COMMIT_UNIQUE 10eb45ca diff --git a/include/outcome/experimental/result.h b/include/outcome/experimental/result.h index fd45369dec..b9d9b5e6d9 100644 --- a/include/outcome/experimental/result.h +++ b/include/outcome/experimental/result.h @@ -155,6 +155,7 @@ extern "C" #define CXX_RESULT_STATUS_CODE(ident) struct cxx_result_status_code_##ident +#define CXX_TO_RESULT_STATUS_CODE(ident, ...) to_##ident(__VA_ARGS__) #define CXX_MAKE_RESULT_STATUS_CODE_SUCCESS(ident, ...) outcome_make_result_##ident##_success(__VA_ARGS__) #define CXX_MAKE_RESULT_STATUS_CODE_FAILURE_POSIX(ident, ...) outcome_make_result_##ident##_failure_posix(__VA_ARGS__) #define CXX_MAKE_RESULT_STATUS_CODE_FAILURE_SYSTEM(ident, ...) outcome_make_result_##ident##_failure_system(__VA_ARGS__) @@ -176,6 +177,7 @@ extern "C" #define CXX_DECLARE_RESULT_SYSTEM(ident, R) CXX_DECLARE_RESULT_STATUS_CODE(system_##ident, R, struct cxx_status_code_system) #define CXX_RESULT_SYSTEM(ident) CXX_RESULT_STATUS_CODE(system_##ident) +#define CXX_TO_RESULT_SYSTEM_CODE(ident, ...) to_system_##ident(__VA_ARGS__) #define CXX_MAKE_RESULT_SYSTEM_SUCCESS(ident, ...) CXX_MAKE_RESULT_STATUS_CODE_SUCCESS(system_##ident, __VA_ARGS__) #define CXX_MAKE_RESULT_SYSTEM_FAILURE_POSIX(ident, ...) CXX_MAKE_RESULT_STATUS_CODE_FAILURE_POSIX(system_##ident, __VA_ARGS__) #define CXX_MAKE_RESULT_SYSTEM_FAILURE_SYSTEM(ident, ...) CXX_MAKE_RESULT_STATUS_CODE_FAILURE_SYSTEM(system_##ident, __VA_ARGS__)