Add M_INIT_VAI to initialize a container with a VA.
(pretty much like it was done for ALGO). Use if for array & list so that you can init them in M_LET by giving it a VA.
This commit is contained in:
1 parent
0e717389c1
commit
822c27399c
4 files changed
+17
-2
No files matched your search
@@ -53,6 +53,7 @@
|
||||
#define ARRAYI_OPLIST2(name, oplist) \
|
||||
(INIT(M_C(name, _init)) \
|
||||
,INIT_SET(M_C(name, _init_set)) \
|
||||
,INIT_WITH(API_1(M_INIT_VAI)) \
|
||||
,SET(M_C(name, _set)) \
|
||||
,CLEAR(M_C(name, _clear)) \
|
||||
,INIT_MOVE(M_C(name, _init_move)) \
|
||||
|
||||
@@ -1066,7 +1066,8 @@
|
||||
#define M_MAP_C(f, ...) M_REDUCE(f, M_ID, __VA_ARGS__)
|
||||
|
||||
/* M_MAP2_C(f, d, a, b, c) ==> f(d, a), f(d, b), f(d, c) */
|
||||
#define M_MAP2_C(f, d, ...) M_REDUCE2(f, M_ID, d, __VA_ARGS__)
|
||||
#define M_MAP2_C(f, d, ...) M_REDUCE2(f, M_MAP2_C_ID, d, __VA_ARGS__)
|
||||
#define M_MAP2_C_ID(...) __VA_ARGS__
|
||||
|
||||
|
||||
/* Sequence of numerical */
|
||||
@@ -2180,13 +2181,20 @@ m_core_hash (const void *str, size_t length)
|
||||
(M_GET_CLEAR oplist (name), cont = false)) \
|
||||
for(;cont;cont = false)
|
||||
#define M_LETI_SINGLE2_INIT(oplist, name, ...) \
|
||||
M_IF_METHOD(INIT_WITH,oplist)(M_GET_INIT_WITH oplist (name, __VA_ARGS__), M_GET_INIT_SET oplist (name, __VA_ARGS__))
|
||||
M_IF_METHOD(INIT_WITH,oplist)(M_CALL_INIT_WITH(oplist, name, __VA_ARGS__), M_GET_INIT_SET oplist (name, __VA_ARGS__))
|
||||
|
||||
/* Transform the va list by adding their number as the first argument of
|
||||
the list.
|
||||
Example: M_VA(a,b,c,d,e) ==> 5,a,b,c,d,e */
|
||||
#define M_VA(...) M_NARGS(__VA_ARGS__), __VA_ARGS__
|
||||
|
||||
/* Initialize the continaer 'dest' with oplist and fill in with the VA arguments */
|
||||
#define M_INIT_VAI(oplist, dest, ...) \
|
||||
(void)(M_GET_INIT oplist (dest) , \
|
||||
M_MAP2_C(M_INIT_VAI_FUNC, (dest, M_GET_PUSH oplist) , __VA_ARGS__))
|
||||
#define M_INIT_VAI_FUNC(d, a) \
|
||||
M_PAIR_2 d (M_PAIR_1 d, a)
|
||||
|
||||
|
||||
/************************************************************/
|
||||
/********************* MEMORY handling **********************/
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
#define LISTI_OPLIST2(name, oplist) \
|
||||
(INIT(M_C(name, _init)), \
|
||||
INIT_SET(M_C(name, _init_set)), \
|
||||
INIT_WITH(API_1(M_INIT_VAI)), \
|
||||
SET(M_C(name, _set)), \
|
||||
CLEAR(M_C(name, _clear)), \
|
||||
MOVE(M_C(name, _move)), \
|
||||
|
||||
@@ -618,6 +618,11 @@ static void test_out_default_oplist(void)
|
||||
assert (list_int_equal_p(l2, list));
|
||||
fclose(f);
|
||||
}
|
||||
M_LET(str, string_t)
|
||||
M_LET( (list, 1, 2, 3, 4, 5), list_int_t) {
|
||||
list_int_get_str(str, list, false);
|
||||
assert (string_equal_str_p(str, "[5,4,3,2,1]"));
|
||||
}
|
||||
}
|
||||
#else
|
||||
static void test_out_default_oplist(void)
|
||||
|
||||
Reference in new issue
Block a user