From f428acdaf8c8851323391a949f0a9cbcf521adda Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sat, 31 May 2025 11:41:42 -0600 Subject: libmisc: macro.h, wrap-cc: Implement LM_DEFAPPEND --- libmisc/include/libmisc/macro.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'libmisc/include') diff --git a/libmisc/include/libmisc/macro.h b/libmisc/include/libmisc/macro.h index 2531587..48f52e5 100644 --- a/libmisc/include/libmisc/macro.h +++ b/libmisc/include/libmisc/macro.h @@ -170,4 +170,18 @@ /** The same as LM_FOREACH_TUPLE(), but callable from inside of LM_FOREACH_TUPLE(). */ #define LM_FOREACH_TUPLE2(...) _LM_DEFER2(_LM_FOREACH_TUPLE_indirect)()(__VA_ARGS__) +/* CPP: wrap-cc extensions ****************************************************/ + +#ifdef __LIBMISC_ENHANCED_CPP__ +/** + * `LM_DEFAPPEND(macro, val)` is like `#define macro val`, but can (1) + * be used from inside of a macro, and (2) appends to a value if it is + * already defined with LM_DEFAPPEND. There are lots of edge-cases, + * don't get cute. + */ +#define LM_DEFAPPEND(macro, ...) __xx__LM_DEFAPPEND__xx__(#macro, #__VA_ARGS__) LM_FORCE_SEMICOLON +#define LM_DEFAPPEND_(macro, ...) _LM_DEFAPPEND_(#macro, __VA_ARGS__) +#define _LM_DEFAPPEND_(macrostr, ...) __xx__LM_DEFAPPEND__xx__(macrostr, #__VA_ARGS__) LM_FORCE_SEMICOLON +#endif + #endif /* _LIBMISC_MACRO_H_ */ -- cgit v1.2.3-2-g168b