diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-31 11:41:42 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-06-02 17:03:08 -0600 |
commit | cc8b1b019d2b1d9ff2f1b9fd0aab0cae6d7cf96e (patch) | |
tree | ca8a875b172f01afc97164c8462ab7549aae97e9 /libmisc/include | |
parent | ce8ae41d677875adb45d99c351bcba108fb82a44 (diff) |
wip: libmisc: Move FOREACH into wrap-cclukeshu/wrap-foreach
Diffstat (limited to 'libmisc/include')
-rw-r--r-- | libmisc/include/libmisc/macro.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libmisc/include/libmisc/macro.h b/libmisc/include/libmisc/macro.h index 48f52e5..011d61f 100644 --- a/libmisc/include/libmisc/macro.h +++ b/libmisc/include/libmisc/macro.h @@ -116,6 +116,9 @@ /* CPP: iteration *************************************************************/ +#ifdef __LIBMISC_ENHANCED_CPP__ +#define _LM_EVAL(...) __xx_LM_EVAL_xx__(__VA_ARGS__) +#else /* The desire to support a high number of iterations is in competition * with the desire for short compile times. 16 is the lowest * power-of-2 for which the current code compiles. */ @@ -125,6 +128,7 @@ #define _LM_EVAL__4(...) _LM_EVAL__2(_LM_EVAL__2(__VA_ARGS__)) #define _LM_EVAL__2(...) _LM_EVAL__1(_LM_EVAL__1(__VA_ARGS__)) #define _LM_EVAL__1(...) __VA_ARGS__ +#endif #define _LM_DEFER2(macro) macro LM_EAT LM_EAT()() @@ -135,6 +139,9 @@ * BUG: LM_FOREACH_PARAM is limited to (16*2)-1=31 params. */ #define LM_FOREACH_PARAM(func, fixedparams, ...) _LM_EVAL(_LM_FOREACH_PARAM(func, fixedparams, __VA_ARGS__)) +#ifdef __LIBMISC_ENHANCED_CPP__ +#define _LM_FOREACH_PARAM(func, fixedparams, ...) __xx_LM_FOREACH_PARAM_xx__(func, fixedparams __VA_OPT__(,) __VA_ARGS__) +#else #define _LM_FOREACH_PARAM(func, fixedparams, ...) _LM_FOREACH_PARAM_ITEM(func, fixedparams, __VA_ARGS__, ()) #define _LM_FOREACH_PARAM_FIXEDPARAMS(fixedparams) _LM_FOREACH_PARAM_FIXEDPARAMS_inner fixedparams #define _LM_FOREACH_PARAM_FIXEDPARAMS_inner(...) __VA_ARGS__ __VA_OPT__(,) @@ -144,9 +151,14 @@ _LM_DEFER2(_LM_FOREACH_PARAM_ITEM_indirect)()(func, fixedparams, __VA_ARGS__) \ ) #define _LM_FOREACH_PARAM_ITEM_indirect() _LM_FOREACH_PARAM_ITEM +#endif /** The same as LM_FOREACH_PARAM(), but callable from inside of LM_FOREACH_PARAM(). */ +#ifdef __LIBMISC_ENHANCED_CPP__ +#define LM_FOREACH_PARAM2 _LM_FOREACH_PARAM +#else #define LM_FOREACH_PARAM2(...) _LM_DEFER2(_LM_FOREACH_PARAM_ITEM_indirect)()(__VA_ARGS__, ()) +#endif /** The same as above, but evaluates the arguments first. */ #define LM_FOREACH_PARAM_(...) LM_FOREACH_PARAM(__VA_ARGS__) @@ -160,15 +172,23 @@ */ #define LM_FOREACH_TUPLE(tuples, func, ...) \ _LM_EVAL(_LM_FOREACH_TUPLE(tuples, func, __VA_ARGS__)) +#ifdef __LIBMISC_ENHANCED_CPP__ +#define _LM_FOREACH_TUPLE(tuples, func, ...) __xx_LM_FOREACH_TUPLE_xx__(tuples, func __VA_OPT__(,) __VA_ARGS__) +#else #define _LM_FOREACH_TUPLE(tuples, func, ...) \ LM_IF(LM_TUPLES_IS_NONEMPTY(tuples))( \ _LM_DEFER2(func)(__VA_ARGS__ __VA_OPT__(,) LM_EXPAND LM_TUPLES_HEAD(tuples)) \ _LM_DEFER2(_LM_FOREACH_TUPLE_indirect)()(LM_TUPLES_TAIL(tuples), func, __VA_ARGS__) \ )() #define _LM_FOREACH_TUPLE_indirect() _LM_FOREACH_TUPLE +#endif /** The same as LM_FOREACH_TUPLE(), but callable from inside of LM_FOREACH_TUPLE(). */ +#ifdef __LIBMISC_ENHANCED_CPP__ +#define LM_FOREACH_TUPLE2 _LM_FOREACH_TUPLE +#else #define LM_FOREACH_TUPLE2(...) _LM_DEFER2(_LM_FOREACH_TUPLE_indirect)()(__VA_ARGS__) +#endif /* CPP: wrap-cc extensions ****************************************************/ |