Add M_REPLICATE & M_REPLICATE_C (src, test, doc)

This commit is contained in:
Patrick Pelissier committed 2021-02-06 22:32:38 +01:00
1 parent 07eb5697ab
commit 0cb1a8054f
3 files changed
+28

No files matched your search

+16
View File
@@ -5694,6 +5694,22 @@ Generate a sequence of number from 'init' to 'end'
==>
1,2,3,4,5,6
##### M\_REPLICATE(N, value)
Replicate the value 'value' N times.
M_REPLICATE(5, D)
==>
D D D D D
##### M\_REPLICATE\_C(N, value)
Replicate the value 'value' N times, separating then by commas.
M_REPLICATE_C(5, D)
==>
D , D , D , D , D
##### M\_NARGS(args...)
Return the number of argument of the given list.
+8
View File
@@ -1567,6 +1567,14 @@ M_BEGIN_PROTECTED_CODE
*/
#define M_SEQ(init, end) M_MID_ARGS(init, M_INC(M_SUB(end, init)), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52)
/* Replicate the value 'N' times */
#define M_REPLICATE(N, value) \
M_MAP2(M_RET_ARG1, value, M_SEQ(1, N))
/* Replicate the value 'N' times, separated by commas */
#define M_REPLICATE_C(N, value) \
M_MAP2_C(M_RET_ARG1, value, M_SEQ(1, N))
/* Return the input (delay evaluation) */
#define M_ID(...) __VA_ARGS__
+4
View File
@@ -305,6 +305,10 @@ static void test_list(void)
assert(M_KEEP_ARGS(1, 1, 0, 0, 0, 0));
assert(M_SKIP_ARGS(4, 0, 0, 0, 0, 1));
assert(M_MID_ARGS(2, 1, 0, 0, 1, 0));
const int tab[] = { M_REPLICATE_C(5, 1) };
for(int i = 0; i < 5; i++) assert(tab[i] == 1);
const char str[] = M_REPLICATE(10, "N");
assert(strcmp(str, "NNNNNNNNNN") == 0);
}
static void test_oplist(void)