diff options
author | Alistair Popple <alistair@popple.id.au> | 2018-06-20 15:34:05 +1000 |
---|---|---|
committer | Alistair Popple <alistair@popple.id.au> | 2018-06-25 15:57:55 +1000 |
commit | 5dcbfeedc091fead3a6ef21af3000d4e256c3355 (patch) | |
tree | d6466aad12a90f5aac523c6928e2610fd24fcc64 /ccan/cppmagic | |
parent | 0b9decd0831bfad3cec0b79e776edc23b7c220ce (diff) | |
download | pdbg-5dcbfeedc091fead3a6ef21af3000d4e256c3355.tar.gz pdbg-5dcbfeedc091fead3a6ef21af3000d4e256c3355.zip |
ccan/cppmaigc: Add CPPMAGIC_MAP_CNT(...) macro
It can be useful to have a count to keep track of which argument number in the
list is being expanded.
Signed-off-by: Alistair Popple <alistair@popple.id.au>
Diffstat (limited to 'ccan/cppmagic')
-rw-r--r-- | ccan/cppmagic/cppmagic.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/ccan/cppmagic/cppmagic.h b/ccan/cppmagic/cppmagic.h index ffd5848..4cfb892 100644 --- a/ccan/cppmagic/cppmagic.h +++ b/ccan/cppmagic/cppmagic.h @@ -177,6 +177,25 @@ () /** + * CPPMAGIC_MAP_CNT - iterate antoher macro across arguments adding a count + * @m: name of a two argument macro + * + * CPPMAGIC_MAP_CNT(@m, @a1, @a2, ..., @an) + * expands to the expansion of + * @m(0, @a1) , @m(1, @a2) , ... , @m(n - 1, @an) + */ +#define _CPPMAGIC_MAP_CNT_() _CPPMAGIC_MAP_CNT +#define _CPPMAGIC_MAP_CNT(m_, c_, a_, ...) \ + m_(c_, a_) \ + CPPMAGIC_IFELSE(CPPMAGIC_NONEMPTY(__VA_ARGS__)) \ + (, CPPMAGIC_DEFER2(_CPPMAGIC_MAP_CNT_)()(m_, CPPMAGIC_INC(c_), __VA_ARGS__)) \ + () +#define CPPMAGIC_MAP_CNT(m_, ...) \ + CPPMAGIC_IFELSE(CPPMAGIC_NONEMPTY(__VA_ARGS__)) \ + (CPPMAGIC_EVAL(_CPPMAGIC_MAP_CNT(m_, 0, __VA_ARGS__))) \ + () + +/** * CPPMAGIC_JOIN - separate arguments with given delimiter * @d: delimiter * |