File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change 33 * @brief C type deletion registration
44 * @date 2024-10-29
55 *
6- * This file is used to define how to "delete" C types that acts as owners or
6+ * This file is used to define how to "delete" C types that acts as owners of
77 * resources.
88 *
99 * Refer to `dev/deletion` for details
1212
1313#include < mlib/config.h>
1414
15- #if mlib_is_cxx()
16- #include < type_traits>
17- #endif
18-
1915/* *
2016 * @brief Use inline within a struct to declare a deletion spec that invokes
2117 * a deletion on struct members. In C, expands to an empty declaration.
3531 }) \
3632 mlib_static_assert(true , " " )
3733
34+ // clang-format off
3835/* *
3936 * @brief Declares a C API function `FuncName` that invokes the default deletion
4037 * method for `Type`.
4744 */
4845#define mlib_declare_c_deletion_function (FuncName, Type ) \
4946 MLIB_IF_ELSE (mlib_have_cxx20()) \
47+ /* -
48+ * If C++ declare and define an inline deleter function that just invokes the delete_unique()
49+ * for the given type.
50+ */ \
5051 (extern " C" MLIB_IF_GNU_LIKE([[gnu::used]]) inline void FuncName(Type inst) noexcept { \
5152 ::mlib::delete_unique (inst); \
52- } static_assert (true , " " )) /* */ \
53- (void FuncName (Type inst))
53+ }) \
54+ /* -
55+ * If C, just declares the function signature, which will be defined in some C++ translation
56+ * unit.
57+ */ \
58+ (void FuncName (Type inst);) \
59+ /* Trailing static-assert to force a semicolon */ \
60+ mlib_static_assert (true , " " )
61+ // clang-format on
5462
5563#if mlib_is_cxx()
5664
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ struct deferred_conversion {
2121 mlib::object_t <F> _func;
2222
2323 // Need to use std::invoke_result for MSVC bugs, not mlib::invoke_result
24- constexpr operator std::invoke_result_t <F>() { return std ::invoke (static_cast <F&&>(_func)); }
24+ constexpr operator std::invoke_result_t <F>() { return mlib ::invoke (static_cast <F&&>(_func)); }
2525
2626 constexpr operator std::invoke_result_t <const F>() const {
2727 return mlib::invoke (static_cast <F const &&>(_func));
You can’t perform that action at this time.
0 commit comments