Reformat macro to 80 characters

This commit is contained in:
Patrick Pelissier committed 2020-10-21 23:23:40 +02:00
1 parent 8a0a556604
commit 54d4b80368
27 files changed
+12821 -12821

No files matched your search

+171 -171
View File
@@ -31,18 +31,18 @@
which oplist is 'contOp', as static inline functions.
USAGE:
ALGO_DEF(algogName, containerOplist|type if oplist has been registered) */
#define ALGO_DEF(name, cont_oplist) \
M_BEGIN_PROTECTED_CODE \
ALGOI_DEF_P1(name, M_GLOBAL_OPLIST(cont_oplist)) \
#define ALGO_DEF(name, cont_oplist) \
M_BEGIN_PROTECTED_CODE \
ALGOI_DEF_P1(name, M_GLOBAL_OPLIST(cont_oplist)) \
M_END_PROTECTED_CODE
/* Map a function (or a macro) to all elements of a container.
USAGE:
ALGO_FOR_EACH(container, containerOplist, function[, extra arguments of function]) */
#define ALGO_FOR_EACH(container, cont_oplist, ...) \
M_IF_NARGS_EQ1(__VA_ARGS__) \
(ALGOI_FOR_EACH(container, M_GLOBAL_OPLIST(cont_oplist), __VA_ARGS__), \
#define ALGO_FOR_EACH(container, cont_oplist, ...) \
M_IF_NARGS_EQ1(__VA_ARGS__) \
(ALGOI_FOR_EACH(container, M_GLOBAL_OPLIST(cont_oplist), __VA_ARGS__), \
ALGOI_FOR_EACH_ARG(container, M_GLOBAL_OPLIST(cont_oplist), __VA_ARGS__ ))
@@ -51,8 +51,8 @@
USAGE:
ALGO_TRANSFORM(contDst, contDOplist, contSrc, contSrcOplist,
function[, extra arguments of function]) */
#define ALGO_TRANSFORM(contD, contDop, contS, contSop, ...) \
M_IF_NARGS_EQ1(__VA_ARGS__) \
#define ALGO_TRANSFORM(contD, contDop, contS, contSop, ...) \
M_IF_NARGS_EQ1(__VA_ARGS__) \
(ALGOI_TRANSFORM(contD, M_GLOBAL_OPLIST(contDop), contS, M_GLOBAL_OPLIST(contSop), __VA_ARGS__), \
ALGOI_TRANSFORM_ARG(contD, M_GLOBAL_OPLIST(contDop), contS, M_GLOBAL_OPLIST(contSop), __VA_ARGS__ ))
@@ -61,10 +61,10 @@
USAGE:
ALGO_EXTRACT(contDst, contDstOplist, contSrc, contSrcOplist
[, function [, extra arguments of function]]) */
#define ALGO_EXTRACT(contD, contDop, contS, ...) \
M_IF_NARGS_EQ1(__VA_ARGS__) \
#define ALGO_EXTRACT(contD, contDop, contS, ...) \
M_IF_NARGS_EQ1(__VA_ARGS__) \
(ALGOI_EXTRACT(contD, M_GLOBAL_OPLIST(contDop), M_GLOBAL_OPLIST(contS), __VA_ARGS__), \
M_IF_NARGS_EQ2(__VA_ARGS__) \
M_IF_NARGS_EQ2(__VA_ARGS__) \
(ALGOI_EXTRACT_FUNC(contD, M_GLOBAL_OPLIST(contDop), M_GLOBAL_OPLIST(contS), __VA_ARGS__), \
ALGOI_EXTRACT_ARG(contD, M_GLOBAL_OPLIST(contDop), M_GLOBAL_OPLIST(contS), __VA_ARGS__ )))
@@ -73,8 +73,8 @@
USAGE:
ALGO_REDUCE(dstVar, container, contOplist, reduceFunc
[, mapFunc[, extraParameters of map function]]) */
#define ALGO_REDUCE(dest, cont, contOp, ...) \
M_IF(M_PARENTHESIS_P(dest)) \
#define ALGO_REDUCE(dest, cont, contOp, ...) \
M_IF(M_PARENTHESIS_P(dest)) \
(ALGOI_REDUCE_DISPATCH(M_PAIR_1 dest, M_GLOBAL_OPLIST(M_PAIR_2 dest), M_GLOBAL_TYPE(M_PAIR_2 dest),cont, M_GLOBAL_OPLIST(contOp), __VA_ARGS__), \
ALGOI_REDUCE_DISPATCH(dest, M_GET_OPLIST M_GLOBAL_OPLIST(contOp), M_GET_SUBTYPE M_GLOBAL_OPLIST(contOp), cont, contOp, __VA_ARGS__)) \
@@ -84,7 +84,7 @@
ALGO_INIT_VA(container, containerOplist, param1[, param2[, ...]]).
OBSOLETE: WILL BE DELETED.
*/
#define ALGO_INIT_VA(dest, contOp, ...) \
#define ALGO_INIT_VA(dest, contOp, ...) \
ALGO_INIT_VAI(dest, M_GLOBAL_OPLIST(contOp), __VA_ARGS__)
@@ -95,7 +95,7 @@
}
OBSOLETE: WILL BE DELETED.
*/
#define ALGO_LET_INIT_VA(dest, contOp, ...) \
#define ALGO_LET_INIT_VA(dest, contOp, ...) \
ALGO_LET_INIT_VAI(dest, M_GLOBAL_OPLIST(contOp), __VA_ARGS__)
@@ -104,16 +104,16 @@
USAGE:
ALGO_INSERT_AT(containerDst, containerDstOPLIST|containerDstType, containerDstIterator, containerSrc, containerSrcOPLIST|containerSrcType)
*/
#define ALGO_INSERT_AT(contDst, contDstOp, position, contSrc, contSrcOp) \
#define ALGO_INSERT_AT(contDst, contDstOp, position, contSrc, contSrcOp) \
ALGOI_INSERT_AT(contDst, M_GLOBAL_OPLIST(contDstOp), position, contSrc, M_GLOBAL_OPLIST(contSrcOp) )
/********************************** INTERNAL ************************************/
/* Try to expand the algorithms */
#define ALGOI_DEF_P1(name, cont_oplist) \
ALGOI_DEF_P2(name, M_GET_TYPE cont_oplist, cont_oplist, \
M_GET_SUBTYPE cont_oplist, M_GET_OPLIST cont_oplist, \
#define ALGOI_DEF_P1(name, cont_oplist) \
ALGOI_DEF_P2(name, M_GET_TYPE cont_oplist, cont_oplist, \
M_GET_SUBTYPE cont_oplist, M_GET_OPLIST cont_oplist, \
M_GET_IT_TYPE cont_oplist)
/* First validate the first oplist */
@@ -246,7 +246,7 @@
while (!M_CALL_IT_END_P(cont_oplist, it2)) { \
type_t const *ref1 = M_CALL_IT_CREF(cont_oplist, it1); \
type_t const *ref2 = M_CALL_IT_CREF(cont_oplist, it2); \
if (!(cmp_func(name, sort_name, ref1, ref2) <= 0)) { \
if (!(cmp_func(name, sort_name, ref1, ref2) <= 0)) { \
return false; \
} \
M_CALL_IT_SET(cont_oplist, it1, it2); \
@@ -260,11 +260,11 @@
/* - an unstable merge sort (need 'splice_back' method) */ \
/* - an insertion sort (need 'previous' method) */ \
/* - a selection sort */ \
M_IF(M_AND(M_TEST_METHOD_P(SORT, cont_oplist), M_EMPTY_P(cmp_arg)))( \
/******** OPTIMIZED SORT FOR CONTAINER *********/ \
M_IF(M_AND(M_TEST_METHOD_P(SORT, cont_oplist), M_EMPTY_P(cmp_arg)))( \
/******** OPTIMIZED SORT FOR CONTAINER *********/ \
static inline void M_C(name,sort_name)(container_t l) \
{ \
M_CALL_SORT(cont_oplist, l, M_C3(name, sort_name,_cmp)); \
M_CALL_SORT(cont_oplist, l, M_C3(name, sort_name,_cmp)); \
} \
, \
\
@@ -279,7 +279,7 @@
{ \
it_t it; \
bool b = false; \
/* Split 'l' into 'l1' and 'l2' */ \
/* Split 'l' into 'l1' and 'l2' */ \
for (M_CALL_IT_FIRST(cont_oplist,it, l); \
!M_CALL_IT_END_P(cont_oplist, it);) { \
M_CALL_SPLICE_BACK(cont_oplist, (b ? l1 : l2), l, it); \
@@ -300,14 +300,14 @@
M_CALL_IT_FIRST(cont_oplist,it1, l1); \
M_CALL_IT_FIRST(cont_oplist,it2, l2); \
while (true) { \
/* Compare current elements of the containers l1 and l2 */ \
/* Compare current elements of the containers l1 and l2 */ \
int c = cmp_func(name, sort_name, M_CALL_IT_CREF(cont_oplist, it1), \
M_CALL_IT_CREF(cont_oplist, it2)); \
M_CALL_IT_CREF(cont_oplist, it2)); \
if (c <= 0) { \
/* Move the element of l1 in the new container */ \
/* Move the element of l1 in the new container */ \
M_CALL_SPLICE_AT(cont_oplist, l, it, l1, it1); \
if (M_UNLIKELY (M_CALL_IT_END_P(cont_oplist, it1))) { \
/* Move all remaining elements of l2 in 'l' */ \
/* Move all remaining elements of l2 in 'l' */ \
while (!M_CALL_IT_END_P(cont_oplist, it2)) { \
M_CALL_SPLICE_AT(cont_oplist, l, it, l2, it2); \
} \
@@ -330,7 +330,7 @@
\
/* Sort the container 'l' */ \
static inline void \
M_C(name,sort_name)(container_t l cmp_param(name)) \
M_C(name,sort_name)(container_t l cmp_param(name)) \
{ \
container_t l1; \
container_t l2; \
@@ -350,8 +350,8 @@
if (M_UNLIKELY (M_CALL_IT_END_P(cont_oplist, it))) { \
/* Two elements */ \
int c = cmp_func(name, sort_name, \
M_CALL_IT_CREF(cont_oplist, it1), \
M_CALL_IT_CREF(cont_oplist, it2)); \
M_CALL_IT_CREF(cont_oplist, it1), \
M_CALL_IT_CREF(cont_oplist, it2)); \
if (c > 0) { \
/* SWAP */ \
M_CALL_SPLICE_BACK(cont_oplist, l, l, it2); \
@@ -391,8 +391,8 @@
M_CALL_IT_SET(cont_oplist, it2p1, it1); \
while (!M_CALL_IT_END_P(cont_oplist, it2) \
&& !(cmp_func(name, sort_name, \
M_CALL_IT_CREF(cont_oplist, it2), \
M_CONST_CAST(type_t, &x)) <= 0)) { \
M_CALL_IT_CREF(cont_oplist, it2), \
M_CONST_CAST(type_t, &x)) <= 0)) { \
/* TAB[jp1=j+1] := TAB[j] */ \
memcpy(M_CALL_IT_REF(cont_oplist, it2p1), \
M_CALL_IT_CREF(cont_oplist, it2), sizeof (type_t) ); \
@@ -423,7 +423,7 @@
!M_CALL_IT_END_P(cont_oplist, it2); \
M_CALL_IT_NEXT(cont_oplist, it2)) { \
if (cmp_func(name, sort_name, M_CALL_IT_CREF(cont_oplist, it2), \
M_CALL_IT_CREF(cont_oplist, it_min)) < 0) { \
M_CALL_IT_CREF(cont_oplist, it_min)) < 0) { \
M_CALL_IT_SET(cont_oplist, it_min, it2); \
} \
} \
@@ -463,23 +463,23 @@
if (cmp <= 0) { \
/* The element of dst is before. Go to next element of dst */ \
M_CALL_IT_SET(cont_oplist, itIns, itDst); \
M_CALL_IT_NEXT(cont_oplist, itDst); \
M_CALL_IT_NEXT(cont_oplist, itDst); \
if (cmp == 0) { \
/* Skip same arguments in both lists */ \
M_CALL_IT_NEXT(cont_oplist, itSrc); \
} \
} else { \
/* The element of src is before. */ \
/* insert objSrc before */ \
/* insert objSrc before */ \
/* NOTE: IT_INSERT insert after ==> Need of another iterator */ \
M_CALL_IT_INSERT(cont_oplist, dst, itIns, *objSrc); \
M_CALL_IT_NEXT(cont_oplist, itSrc); \
M_CALL_IT_INSERT(cont_oplist, dst, itIns, *objSrc); \
M_CALL_IT_NEXT(cont_oplist, itSrc); \
} \
} \
while (!M_CALL_IT_END_P(cont_oplist, itSrc)) { \
/* Finish inserting the element of src in dst */ \
type_t *objSrc = M_CALL_IT_REF(cont_oplist, itSrc); \
M_CALL_IT_INSERT(cont_oplist, dst, itIns, *objSrc); \
M_CALL_IT_INSERT(cont_oplist, dst, itIns, *objSrc); \
M_CALL_IT_NEXT(cont_oplist, itSrc); \
} \
} \
@@ -501,7 +501,7 @@
&& !M_CALL_IT_END_P(cont_oplist, itDst)) { \
type_t const *objSrc = M_CALL_IT_CREF(cont_oplist, itSrc); \
type_t const *objDst = M_CALL_IT_CREF(cont_oplist, itDst); \
int cmp = cmp_func(name, sort_name, objDst, objSrc); \
int cmp = cmp_func(name, sort_name, objDst, objSrc); \
if (cmp == 0) { \
/* Keep it */ \
M_CALL_IT_NEXT(cont_oplist, itSrc); \
@@ -677,7 +677,7 @@
M_CALL_IT_NEXT(cont_oplist, it1), \
M_CALL_IT_NEXT(cont_oplist, it2)) { \
if (!call_eq(func, *M_CALL_IT_CREF(cont_oplist, it1), \
*M_CALL_IT_CREF(cont_oplist, it2))) \
*M_CALL_IT_CREF(cont_oplist, it2))) \
break; \
} \
} \
@@ -696,7 +696,7 @@
/* Define the FILL algorithms */
#define ALGOI_FILL_DEF_P5(name, container_t, cont_oplist, type_t, type_oplist, it_t) \
\
/* Fill all the container with value (overwritten) */ \
/* Fill all the container with value (overwritten) */ \
static inline void \
M_C(name, _fill) (container_t l, type_t const value) \
{ \
@@ -841,7 +841,7 @@
\
static inline bool \
M_C4(name, _all_of, suffix, p) (container_t const l, \
func_t func ) \
func_t func ) \
{ \
for M_EACH(item, l, cont_oplist) { \
if (!call(func, *item)) \
@@ -1051,93 +1051,93 @@
// _flatten (takes a set of containers and returns a new container containing all flatten objects)
#define ALGOI_FOR_EACH(container, cont_oplist, func) do { \
for M_EACH(_item, container, cont_oplist) { \
func(*_item); \
} \
#define ALGOI_FOR_EACH(container, cont_oplist, func) do { \
for M_EACH(_item, container, cont_oplist) { \
func(*_item); \
} \
} while (0)
#define ALGOI_FOR_EACH_ARG(container, cont_oplist, func, ...) do { \
for M_EACH(_item, container, cont_oplist) { \
func(__VA_ARGS__, *_item); \
} \
#define ALGOI_FOR_EACH_ARG(container, cont_oplist, func, ...) do { \
for M_EACH(_item, container, cont_oplist) { \
func(__VA_ARGS__, *_item); \
} \
} while (0)
#define ALGOI_TRANSFORM(contD, contDop, contS, contSop, func) do { \
M_CALL_CLEAN(contDop, contD); \
for M_EACH(_item, contS, contSop) { \
M_GET_SUBTYPE contDop _tmp; \
M_CALL_INIT(M_GET_OPLIST contDop, _tmp); \
func(_tmp, *_item); \
M_CALL_PUSH_MOVE(contDop, contD, &_tmp); \
} \
M_IF_METHOD(REVERSE, contDop) (M_CALL_REVERSE(contDop, contD);, ) \
#define ALGOI_TRANSFORM(contD, contDop, contS, contSop, func) do { \
M_CALL_CLEAN(contDop, contD); \
for M_EACH(_item, contS, contSop) { \
M_GET_SUBTYPE contDop _tmp; \
M_CALL_INIT(M_GET_OPLIST contDop, _tmp); \
func(_tmp, *_item); \
M_CALL_PUSH_MOVE(contDop, contD, &_tmp); \
} \
M_IF_METHOD(REVERSE, contDop) (M_CALL_REVERSE(contDop, contD);, ) \
} while (0)
#define ALGOI_TRANSFORM_ARG(contD, contDop, contS, contSop, func, ...) do { \
M_CALL_CLEAN(contDop, contD); \
for M_EACH(_item, contS, contSop) { \
M_GET_SUBTYPE contDop _tmp; \
M_CALL_INIT(M_GET_OPLIST contDop, _tmp); \
func(_tmp, *_item, __VA_ARGS__); \
M_CALL_PUSH_MOVE(contDop, contD, &_tmp); \
} \
M_IF_METHOD(REVERSE, contDop) (M_CALL_REVERSE(contDop, contD);, ) \
#define ALGOI_TRANSFORM_ARG(contD, contDop, contS, contSop, func, ...) do { \
M_CALL_CLEAN(contDop, contD); \
for M_EACH(_item, contS, contSop) { \
M_GET_SUBTYPE contDop _tmp; \
M_CALL_INIT(M_GET_OPLIST contDop, _tmp); \
func(_tmp, *_item, __VA_ARGS__); \
M_CALL_PUSH_MOVE(contDop, contD, &_tmp); \
} \
M_IF_METHOD(REVERSE, contDop) (M_CALL_REVERSE(contDop, contD);, ) \
} while (0)
#define ALGOI_EXTRACT(contDst, contDstOplist, \
contSrc, contSrcOplist) do { \
M_CALL_CLEAN(contDstOplist, contDst); \
for M_EACH(_item, contSrc, contSrcOplist) { \
M_IF_METHOD(PUSH, contDstOplist)( \
M_CALL_PUSH(contDstOplist, contDst, *_item); \
, \
#define ALGOI_EXTRACT(contDst, contDstOplist, \
contSrc, contSrcOplist) do { \
M_CALL_CLEAN(contDstOplist, contDst); \
for M_EACH(_item, contSrc, contSrcOplist) { \
M_IF_METHOD(PUSH, contDstOplist)( \
M_CALL_PUSH(contDstOplist, contDst, *_item); \
, \
M_CALL_SET_KEY(contDstOplist, contDst, (*_item).key, (*_item).value); \
) \
} \
) \
} \
M_IF_METHOD(REVERSE, contDstOplist) (M_CALL_REVERSE(contDstOplist, contDst);, ) \
} while (0)
#define ALGOI_EXTRACT_FUNC(contDst, contDstOplist, \
contSrc, contSrcOplist, \
condFunc) do { \
M_CALL_CLEAN(contDstOplist, contDst); \
for M_EACH(_item, contSrc, contSrcOplist) { \
if (condFunc (*_item)) { \
M_IF_METHOD(PUSH, contDstOplist)( \
M_CALL_PUSH(contDstOplist, contDst, *_item); \
, \
#define ALGOI_EXTRACT_FUNC(contDst, contDstOplist, \
contSrc, contSrcOplist, \
condFunc) do { \
M_CALL_CLEAN(contDstOplist, contDst); \
for M_EACH(_item, contSrc, contSrcOplist) { \
if (condFunc (*_item)) { \
M_IF_METHOD(PUSH, contDstOplist)( \
M_CALL_PUSH(contDstOplist, contDst, *_item); \
, \
M_CALL_SET_KEY(contDstOplist, contDst, (*_item).key, (*_item).value); \
) \
} \
} \
) \
} \
} \
M_IF_METHOD(REVERSE, contDstOplist) (M_CALL_REVERSE(contDstOplist, contDst);, ) \
} while (0)
#define ALGOI_EXTRACT_ARG(contDst, contDstOplist, \
contSrc, contSrcOplist, \
condFunc, ...) do { \
M_CALL_CLEAN(contDstOplist, contDst); \
for M_EACH(_item, contSrc, contSrcOplist) { \
if (condFunc (__VA_ARGS__, *_item)) { \
M_IF_METHOD(PUSH, contDstOplist)( \
M_CALL_PUSH(contDstOplist, contDst, *_item); \
, \
#define ALGOI_EXTRACT_ARG(contDst, contDstOplist, \
contSrc, contSrcOplist, \
condFunc, ...) do { \
M_CALL_CLEAN(contDstOplist, contDst); \
for M_EACH(_item, contSrc, contSrcOplist) { \
if (condFunc (__VA_ARGS__, *_item)) { \
M_IF_METHOD(PUSH, contDstOplist)( \
M_CALL_PUSH(contDstOplist, contDst, *_item); \
, \
M_CALL_SET_KEY(contDstOplist, contDst, (*_item).key, (*_item).value); \
) \
} \
} \
) \
} \
} \
M_IF_METHOD(REVERSE, contDstOplist) (M_CALL_REVERSE(contDstOplist, contDstOplist);, ) \
} while (0)
#define ALGOI_REDUCE_DISPATCH(dest, destOp, dest_t, cont, contOp, ...) \
M_IF_NARGS_EQ1(__VA_ARGS__) \
(ALGOI_REDUCE_BASIC(dest, dest_t, destOp, cont, contOp, __VA_ARGS__), \
M_IF_NARGS_EQ2(__VA_ARGS__) \
(ALGOI_REDUCE_FOR_EACH(dest, dest_t, destOp, cont, contOp, __VA_ARGS__), \
#define ALGOI_REDUCE_DISPATCH(dest, destOp, dest_t, cont, contOp, ...) \
M_IF_NARGS_EQ1(__VA_ARGS__) \
(ALGOI_REDUCE_BASIC(dest, dest_t, destOp, cont, contOp, __VA_ARGS__), \
M_IF_NARGS_EQ2(__VA_ARGS__) \
(ALGOI_REDUCE_FOR_EACH(dest, dest_t, destOp, cont, contOp, __VA_ARGS__), \
ALGOI_REDUCE_FOR_EACH_ARG(dest, dest_t, destOp, cont, contOp, __VA_ARGS__) ) )
/* The special functions handled by ALGO_REDUCE */
@@ -1149,94 +1149,94 @@
/* Return the method associated to a reduce operation.
It returns the special function handler if function is and, or, sum or add.
Otherwise it returns the original function */
#define ALGOI_REDUCE_FUNC(reduceFunc) \
M_IF(M_KEYWORD_P(and, reduceFunc)) \
(ALGOI_REDUCE_AND, \
M_IF(M_KEYWORD_P(or, reduceFunc)) \
(ALGOI_REDUCE_OR, \
M_IF(M_KEYWORD_P(sum, reduceFunc)) \
(ALGOI_REDUCE_SUM, \
M_IF(M_KEYWORD_P(product, reduceFunc)) \
(ALGOI_REDUCE_PRODUCT, \
reduceFunc) \
) \
) \
#define ALGOI_REDUCE_FUNC(reduceFunc) \
M_IF(M_KEYWORD_P(and, reduceFunc)) \
(ALGOI_REDUCE_AND, \
M_IF(M_KEYWORD_P(or, reduceFunc)) \
(ALGOI_REDUCE_OR, \
M_IF(M_KEYWORD_P(sum, reduceFunc)) \
(ALGOI_REDUCE_SUM, \
M_IF(M_KEYWORD_P(product, reduceFunc)) \
(ALGOI_REDUCE_PRODUCT, \
reduceFunc) \
) \
) \
)
#define ALGOI_REDUCE_BASIC(dest, dest_t, destOp, cont, cont_oplist, reduceFunc) do { \
bool _init_done = false; \
for M_EACH(_item, cont, cont_oplist) { \
if (_init_done) { \
ALGOI_REDUCE_FUNC(reduceFunc) (dest, *_item); \
} else { \
M_CALL_SET(destOp, dest, *_item); \
_init_done = true; \
} \
} \
bool _init_done = false; \
for M_EACH(_item, cont, cont_oplist) { \
if (_init_done) { \
ALGOI_REDUCE_FUNC(reduceFunc) (dest, *_item); \
} else { \
M_CALL_SET(destOp, dest, *_item); \
_init_done = true; \
} \
} \
} while (0)
#define ALGOI_REDUCE_FOR_EACH(dest, dest_t, destOp, cont, cont_oplist, reduceFunc, mapFunc) do { \
bool _init_done = false; \
dest_t _tmp; \
M_CALL_INIT(destOp, _tmp); \
for M_EACH(_item, cont, cont_oplist) { \
mapFunc(_tmp, *_item); \
if (_init_done) { \
ALGOI_REDUCE_FUNC(reduceFunc) (dest, _tmp); \
} else { \
M_CALL_SET(destOp, dest, _tmp); \
_init_done = true; \
} \
} \
M_CALL_CLEAR(destOp, _tmp); \
bool _init_done = false; \
dest_t _tmp; \
M_CALL_INIT(destOp, _tmp); \
for M_EACH(_item, cont, cont_oplist) { \
mapFunc(_tmp, *_item); \
if (_init_done) { \
ALGOI_REDUCE_FUNC(reduceFunc) (dest, _tmp); \
} else { \
M_CALL_SET(destOp, dest, _tmp); \
_init_done = true; \
} \
} \
M_CALL_CLEAR(destOp, _tmp); \
} while (0)
#define ALGOI_REDUCE_FOR_EACH_ARG(dest, dest_t, destOp, cont, cont_oplist, reduceFunc, mapFunc, ...) do { \
bool _init_done = false; \
dest_t _tmp; \
M_CALL_INIT(destOp, _tmp); \
for M_EACH(_item, cont, cont_oplist) { \
mapFunc(_tmp, __VA_ARGS__, *_item); \
if (_init_done) { \
ALGOI_REDUCE_FUNC(reduceFunc) (dest, _tmp); \
} else { \
M_CALL_SET(destOp, dest, _tmp); \
_init_done = true; \
} \
} \
M_CALL_CLEAR(destOp, _tmp); \
bool _init_done = false; \
dest_t _tmp; \
M_CALL_INIT(destOp, _tmp); \
for M_EACH(_item, cont, cont_oplist) { \
mapFunc(_tmp, __VA_ARGS__, *_item); \
if (_init_done) { \
ALGOI_REDUCE_FUNC(reduceFunc) (dest, _tmp); \
} else { \
M_CALL_SET(destOp, dest, _tmp); \
_init_done = true; \
} \
} \
M_CALL_CLEAR(destOp, _tmp); \
} while (0)
#define ALGOI_INIT_VA_FUNC(d, a) \
#define ALGOI_INIT_VA_FUNC(d, a) \
M_RET_ARG2 d (M_RET_ARG1 d, a) M_DEFERRED_COMMA
#define ALGO_INIT_VAI(dest, contOp, ...) \
(void)(M_CALL_INIT(contOp, dest) M_DEFERRED_COMMA \
#define ALGO_INIT_VAI(dest, contOp, ...) \
(void)(M_CALL_INIT(contOp, dest) M_DEFERRED_COMMA \
M_MAP2(ALGOI_INIT_VA_FUNC, (dest, M_GET_PUSH contOp, ) , __VA_ARGS__) \
true)
#define ALGO_LET_INIT_VAI(dest, ...) \
#define ALGO_LET_INIT_VAI(dest, ...) \
ALGOI_LET_INIT_VAI(M_C3(m_cont_, __LINE__, dest), dest, __VA_ARGS__)
#define ALGOI_LET_INIT_VAI(cont, dest, contOp, ...) \
for(bool cont = true; cont ; /* unused */) \
for(M_GET_TYPE contOp dest; \
cont && (ALGO_INIT_VAI (dest, contOp, __VA_ARGS__), true); \
#define ALGOI_LET_INIT_VAI(cont, dest, contOp, ...) \
for(bool cont = true; cont ; /* unused */) \
for(M_GET_TYPE contOp dest; \
cont && (ALGO_INIT_VAI (dest, contOp, __VA_ARGS__), true); \
(M_CALL_CLEAR(contOp, dest), cont = false))
#define ALGOI_INSERT_AT(contDst, contDstOp, position, contSrc, contSrcOp) do { \
M_GET_IT_TYPE contSrcOp _itSrc; \
M_GET_IT_TYPE contDstOp _itDst; \
M_CALL_IT_SET(contDstOp, _itDst, position); \
for (M_CALL_IT_FIRST(contSrcOp, _itSrc, contSrc) ; \
!M_CALL_IT_END_P(contSrcOp, _itSrc) ; \
M_CALL_IT_NEXT(contSrcOp, _itSrc) ) { \
M_CALL_IT_INSERT(contDstOp, contDst, _itDst, \
*M_CALL_IT_CREF(contSrcOp, _itSrc)); \
} \
M_GET_IT_TYPE contSrcOp _itSrc; \
M_GET_IT_TYPE contDstOp _itDst; \
M_CALL_IT_SET(contDstOp, _itDst, position); \
for (M_CALL_IT_FIRST(contSrcOp, _itSrc, contSrc) ; \
!M_CALL_IT_END_P(contSrcOp, _itSrc) ; \
M_CALL_IT_NEXT(contSrcOp, _itSrc) ) { \
M_CALL_IT_INSERT(contDstOp, contDst, _itDst, \
*M_CALL_IT_CREF(contSrcOp, _itSrc)); \
} \
} while (0)
#endif