Add micro utilities macros for handling list
This commit is contained in:
1 parent
823b1974bb
commit
7268551737
2 files changed
+23
No files matched your search
@@ -1675,6 +1675,19 @@ M_BEGIN_PROTECTED_CODE
|
||||
#define M_FILTER_00(d, item) \
|
||||
M_IF(M_PAIR_1 d(M_PAIR_2 d, item))(item, )
|
||||
|
||||
/* Return the HEAD element of a list */
|
||||
#define M_HEAD(x, ...) x
|
||||
|
||||
/* Return the HEAD element of the tail of a list */
|
||||
#define M_HEAD_2(x, y, ...) y
|
||||
|
||||
/* Return the tail sublist of the list (removing the HEAD) */
|
||||
#define M_TAIL(x, ...) __VA_ARGS__
|
||||
|
||||
/* Return the tail sublist of the sublist (removing the 2 first elements) */
|
||||
#define M_TAIL_2(x, y, ...) __VA_ARGS__
|
||||
|
||||
|
||||
/* Concatene two arglists 'a' and 'b',
|
||||
handling the case of empty arglist
|
||||
handling the cases where the arglists are within parenthesis.
|
||||
|
||||
@@ -758,6 +758,15 @@ static void test_properties(void)
|
||||
assert( M_GET_PROPERTY (OP_PROP(), IT_TYPE ) == 2);
|
||||
assert( M_KEYWORD_P( M_GET_PROPERTY (OP_PROP(), INIT_WITH ), priority));
|
||||
}
|
||||
|
||||
static void test_generic_api(void)
|
||||
{
|
||||
assert( M_HEAD(17, 0) == 17);
|
||||
assert( M_TAIL(18, 19) == 19);
|
||||
assert( M_HEAD_2(18, 17, 0) == 17);
|
||||
assert( M_TAIL_2(18, 17, 8) == 8);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_cat();
|
||||
@@ -783,5 +792,6 @@ int main(void)
|
||||
test_str_hash();
|
||||
test_M_CSTR();
|
||||
test_properties();
|
||||
test_generic_api();
|
||||
exit(0);
|
||||
}
|
||||
Reference in new issue
Block a user