Add MACRO M_VA
This commit is contained in:
1 parent
74113de0b2
commit
dd1a7c13f2
2 files changed
+22
-3
No files matched your search
@@ -794,6 +794,15 @@ m_core_hash(const void *ptr, size_t s)
|
|||||||
#define M_IF_METHOD_ALL(method, ...) \
|
#define M_IF_METHOD_ALL(method, ...) \
|
||||||
M_IF(M_REDUCE2(M_TEST_METHOD_P, M_AND, method, __VA_ARGS__))
|
M_IF(M_REDUCE2(M_TEST_METHOD_P, M_AND, method, __VA_ARGS__))
|
||||||
|
|
||||||
|
/* By putting this after a method, we transform the argument list
|
||||||
|
so that the first argument becomes a pointer to the destination. */
|
||||||
|
#define M_IPTR(...) ( & __VA_ARGS__ )
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************************/
|
||||||
|
/******************** Syntax Enhancing **********************/
|
||||||
|
/************************************************************/
|
||||||
|
|
||||||
/* Define M_EACH macro allowing to iterate over a container
|
/* Define M_EACH macro allowing to iterate over a container
|
||||||
First argument will be a created pointer to the underlying type.
|
First argument will be a created pointer to the underlying type.
|
||||||
Example: for M_EACH(item, list, LIST_OPLIST) { action; } */
|
Example: for M_EACH(item, list, LIST_OPLIST) { action; } */
|
||||||
@@ -824,6 +833,7 @@ m_core_hash(const void *ptr, size_t s)
|
|||||||
!M_GET_IT_END_P oplist (iterator) && (item = M_GET_IT_CREF oplist (iterator), true) ; \
|
!M_GET_IT_END_P oplist (iterator) && (item = M_GET_IT_CREF oplist (iterator), true) ; \
|
||||||
M_GET_IT_NEXT oplist (iterator))
|
M_GET_IT_NEXT oplist (iterator))
|
||||||
|
|
||||||
|
|
||||||
/* Define M_LET macro allowing to define, auto init & auto clear an object
|
/* Define M_LET macro allowing to define, auto init & auto clear an object
|
||||||
within the next bracket.
|
within the next bracket.
|
||||||
Example:
|
Example:
|
||||||
@@ -847,9 +857,10 @@ m_core_hash(const void *ptr, size_t s)
|
|||||||
cont && (M_GET_INIT oplist (name), true); \
|
cont && (M_GET_INIT oplist (name), true); \
|
||||||
(M_GET_CLEAR oplist (name), cont = false))
|
(M_GET_CLEAR oplist (name), cont = false))
|
||||||
|
|
||||||
/* By putting this after a method, we transform the argument list
|
/* Transform the va list by adding their number as the first argument of
|
||||||
so that the first argument becomes a pointer to the destination. */
|
the list.
|
||||||
#define M_IPTR(...) ( & __VA_ARGS__ )
|
Example: M_VA(a,b,c,d,e) ==> 5,a,b,c,d,e */
|
||||||
|
#define M_VA(...) M_NARGS(__VA_ARGS__), __VA_ARGS__
|
||||||
|
|
||||||
|
|
||||||
/************************************************************/
|
/************************************************************/
|
||||||
|
|||||||
@@ -145,6 +145,13 @@ static void test_let(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_va(void)
|
||||||
|
{
|
||||||
|
assert (M_RET_ARG1 (M_VA(a),zz) == 1);
|
||||||
|
assert (M_RET_ARG2 (M_VA(17),zz) == 17);
|
||||||
|
assert (M_RET_ARG1 (M_VA(a,b,c),zz) == 3);
|
||||||
|
assert (M_RET_ARG2 (M_VA(17,42,59),zz) == 17);
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
@@ -155,5 +162,6 @@ int main(void)
|
|||||||
test_invert();
|
test_invert();
|
||||||
test_min();
|
test_min();
|
||||||
test_let();
|
test_let();
|
||||||
|
test_va();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user