Modify M_EACH to support container where only IT_CREF is defined

(and not IT_REF).
This commit is contained in:
Patrick Pelissier committed 2017-03-07 22:42:47 +01:00
1 parent 049ff58566
commit ac8c712dbb
1 file changed
+17 -3
+17 -3
View File
@@ -741,10 +741,15 @@ m_core_hash(const void *ptr, size_t s)
First argument will be a created pointer to the underlying type.
Example: for M_EACH(item, list, LIST_OPLIST) { action; } */
#define M_EACH(item, container, oplist) \
M_EACHI(item, container, oplist, M_C(local_iterator_, __LINE__), \
M_C(local_cont_, __LINE__))
M_IF_METHOD(IT_REF, oplist)( \
M_EACHI(item, container, oplist, \
M_C(local_iterator_, __LINE__), \
M_C(local_cont_, __LINE__)), \
M_EACHI2(item, container, oplist, \
M_C(local_iterator_, __LINE__), \
M_C(local_cont_, __LINE__)) )
/* Internal for M_EACH */
/* Internal for M_EACH with M_GET_IT_REF operator */
#define M_EACHI(item,container,oplist, iterator, cont) \
(bool cont = true; cont; cont = false) \
for(M_GET_SUBTYPE oplist *item; cont ; cont = false) \
@@ -753,6 +758,15 @@ m_core_hash(const void *ptr, size_t s)
!M_GET_IT_END_P oplist (iterator) && (item = M_GET_IT_REF oplist (iterator), true) ; \
M_GET_IT_NEXT oplist (iterator))
/* Internal for M_EACH with M_GET_IT_CREF operator */
#define M_EACHI2(item,container,oplist, iterator, cont) \
(bool cont = true; cont; cont = false) \
for(const M_GET_SUBTYPE oplist *item; cont ; cont = false) \
for(M_GET_IT_TYPE oplist iterator; cont ; cont = false) \
for(M_GET_IT_FIRST oplist (iterator, container) ; \
!M_GET_IT_END_P oplist (iterator) && (item = M_GET_IT_CREF oplist (iterator), true) ; \
M_GET_IT_NEXT oplist (iterator))
/* Define M_LET macro allowing to define, auto init & auto clear an object
within the next bracket.
Example: