summaryrefslogtreecommitdiffhomepage
path: root/include/stc/ccommon.h
diff options
context:
space:
mode:
authorTyge Lovset <[email protected]>2023-08-22 10:43:22 +0200
committerTyge Lovset <[email protected]>2023-08-22 10:43:22 +0200
commit5f56f59c6ea7a731efd4eefc1211352f40a8b33f (patch)
tree06bec5efc87728d6aa781186ef7a2061e4761a41 /include/stc/ccommon.h
parent775e507b301621ce4e608efe1d23f52abe0f1aab (diff)
downloadSTC-modified-5f56f59c6ea7a731efd4eefc1211352f40a8b33f.tar.gz
STC-modified-5f56f59c6ea7a731efd4eefc1211352f40a8b33f.zip
Added c_forint and c_for macros as additions to c_forrange.
Diffstat (limited to 'include/stc/ccommon.h')
-rw-r--r--include/stc/ccommon.h16
1 files changed, 9 insertions, 7 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 5c5e87e6..70e225f0 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -198,13 +198,15 @@ STC_INLINE intptr_t cnextpow2(intptr_t n) {
; _.it.ref && (_.key = &_.it.ref->first, _.val = &_.it.ref->second) \
; C##_next(&_.it))
-#define c_forrange(...) c_MACRO_OVERLOAD(c_forrange, __VA_ARGS__)
-#define c_forrange_1(stop) c_forrange_3(_c_i, 0, stop)
-#define c_forrange_2(i, stop) c_forrange_3(i, 0, stop)
-#define c_forrange_3(i, start, stop) \
- for (_llong i=start, _end=(_llong)(stop); i < _end; ++i)
-#define c_forrange_4(i, start, stop, step) \
- for (_llong i=start, _inc=step, _end=(_llong)(stop) - (_inc > 0) \
+#define c_forint(...) c_for(int, __VA_ARGS__)
+#define c_forrange(...) c_for(_llong, __VA_ARGS__)
+#define c_for(...) c_MACRO_OVERLOAD(c_for, __VA_ARGS__)
+#define c_for_2(T, stop) c_for_4(T, _c_i, 0, stop)
+#define c_for_3(T, i, stop) c_for_4(T, i, 0, stop)
+#define c_for_4(T, i, start, stop) \
+ for (T i=start, _end=stop; i < _end; ++i)
+#define c_for_5(T, i, start, stop, step) \
+ for (T i=start, _inc=step, _end=(T)(stop) - (_inc > 0) \
; (_inc > 0) ^ (i > _end); i += _inc)
#ifndef __cplusplus