From a5ea027efc8b3d1e43df65dce042e945c2b48a52 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Tue, 1 Nov 2022 21:57:10 +0100 Subject: Various updates. --- include/stc/ccommon.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'include/stc') diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index d4fd1fb3..b2e40cb3 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -209,18 +209,23 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle, #define c_forrange4(i, start, stop, step) \ for (long long i=start, _inc=step, _end=(stop) - (_inc > 0) \ ; (_inc > 0) ^ (i > _end); i += _inc) - -#define c_forlist(it, T, ...) \ +#ifndef __cplusplus +# define c_forlist(it, T, ...) \ for (struct {T* data; T* ref; int size, index;} \ it = {.data=(T[])__VA_ARGS__, .ref=it.data, .size=sizeof((T[])__VA_ARGS__)/sizeof(T)} \ ; it.index < it.size; ++it.ref, ++it.index) - +#else +# include +# define c_forlist(it, T, ...) \ + for (struct {std::initializer_list list; std::initializer_list::iterator ref; size_t size, index;} \ + it = {.list=__VA_ARGS__, .ref=it.list.begin(), .size=it.list.size()} \ + ; it.index < it.size; ++it.ref, ++it.index) +#endif #define c_with(...) c_MACRO_OVERLOAD(c_with, __VA_ARGS__) #define c_with2(declvar, drop) for (declvar, **_c_i = NULL; !_c_i; ++_c_i, drop) #define c_with3(declvar, pred, drop) for (declvar, **_c_i = NULL; !_c_i && (pred); ++_c_i, drop) #define c_scope(init, drop) for (int _c_i = (init, 0); !_c_i; ++_c_i, drop) #define c_defer(...) for (int _c_i = 0; !_c_i; ++_c_i, __VA_ARGS__) -#define c_breakauto continue #define c_auto(...) c_MACRO_OVERLOAD(c_auto, __VA_ARGS__) #define c_auto2(C, a) \ -- cgit v1.2.3