Skip to content

Commit

Permalink
Add missing docs for previous commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
ned14 committed Jul 17, 2024
1 parent 10eb45c commit 3519b5a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
14 changes: 14 additions & 0 deletions doc/src/content/experimental/c-api/from-c/system_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,19 @@ as per the <code>quick_status_code_from_enum</code> documentation</a>.
from a C enum.
</dl>

The operations available to C++ are:

<dl>
<dt><code>CXX_TO_RESULT_SYSTEM_CODE(ident, status_code&lt;T&gt;)</code>
<dd>Returns a previously declared C Result from its matching C++ <code>status_code<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.

<dt><code>to_result(any C Result)</code>
<dd>This is an overloaded C++ free function which returns the C++ status_code&lt;T&gt;
matching its input C Result.
</dl>

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.
6 changes: 3 additions & 3 deletions include/outcome/detail/revision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions include/outcome/experimental/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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__)
Expand Down

0 comments on commit 3519b5a

Please sign in to comment.