Skip to content

Commit 69c2f6e

Browse files
committed
Add QX_EVAL_EACH(). Fixed arg, varadic macro functions
1 parent 2907306 commit 69c2f6e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/utility/include/qx/utility/qx-macros.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#define __QX_FOR_EACH_NEXT() __QX_FOR_EACH_APPLY_AND_ITERATE
2020
#define __QX_FOR_EACH_NEXT_DELIM() __QX_FOR_EACH_APPLY_AND_ITERATE_DELIM
21+
#define __QX_EVAL_EACH_NEXT() __QX_EVAL_EACH_APPLY_AND_ITERATE
2122

2223
#define __QX_FOR_EACH_APPLY_AND_ITERATE(macro, first, ...) \
2324
macro(first) \
@@ -26,6 +27,10 @@
2627
#define __QX_FOR_EACH_APPLY_AND_ITERATE_DELIM(macro, first, ...) \
2728
macro(first) \
2829
__VA_OPT__(, __QX_FOR_EACH_NEXT_DELIM __QX_MACRO_CALL (macro, __VA_ARGS__))
30+
31+
#define __QX_EVAL_EACH_APPLY_AND_ITERATE(arg, first, ...) \
32+
first(arg) \
33+
__VA_OPT__(__QX_EVAL_EACH_NEXT __QX_MACRO_CALL (arg, __VA_ARGS__))
2934
/*! @endcond */
3035

3136
// User
@@ -43,4 +48,7 @@ inline size_t qHash(const T& t, size_t seed) { \
4348
#define QX_FOR_EACH_DELIM(macro, ...) \
4449
__VA_OPT__(__QX_MACRO_EVALUATE(__QX_FOR_EACH_APPLY_AND_ITERATE_DELIM(macro, __VA_ARGS__)))
4550

51+
#define QX_EVAL_EACH(arg, ...) \
52+
__VA_OPT__(__QX_MACRO_EVALUATE(__QX_EVAL_EACH_APPLY_AND_ITERATE(arg, __VA_ARGS__)))
53+
4654
#endif // QX_MACROS_H

lib/utility/src/qx-macros.dox

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,21 @@
5050
* QX_FOR_EACH_DELIM(F, 1, 4, 10) // -> F(1), F(4), F(10)
5151
* @endcode
5252
*/
53+
54+
/*!
55+
* @def QX_EVAL_EACH(arg, ...)
56+
*
57+
* This function-like macro acts like a fold expression for its variadic arguments.
58+
* It produces the result of calling all trailing macro functions with the argument
59+
* @a arg.
60+
*
61+
* For example:
62+
* @code{.cpp}
63+
* #define F(x) //...
64+
* #define G(x) //...
65+
* #define H(x) //...
66+
* QX_EVAL_EACH(10, F, G, H) // -> F(10) G(10) H(10)
67+
* @endcode
68+
*
69+
* @sa QX_FOR_EACH()
70+
*/

0 commit comments

Comments
 (0)