diff --git a/m-array.h b/m-array.h index 21ef09fd..ec947387 100644 --- a/m-array.h +++ b/m-array.h @@ -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)) \ diff --git a/m-core.h b/m-core.h index 2cf6170f..89ea752d 100644 --- a/m-core.h +++ b/m-core.h @@ -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 **********************/ diff --git a/m-list.h b/m-list.h index 16825d76..db34bf09 100644 --- a/m-list.h +++ b/m-list.h @@ -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)), \ diff --git a/tests/test-mlist.c b/tests/test-mlist.c index 77abd844..32557052 100644 --- a/tests/test-mlist.c +++ b/tests/test-mlist.c @@ -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)