diff options
| author | Tyge Løvset <[email protected]> | 2022-05-22 20:52:18 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-05-22 20:52:18 +0200 |
| commit | 1c3e7b683469904d224f3f8f1ee0096f1c5b1b9d (patch) | |
| tree | 826ca6560cd952996eb9793cb3356a9791753f2e /include | |
| parent | 314a41be6b39b6c5967d79555dbf018dbc7eb5f6 (diff) | |
| download | STC-modified-1c3e7b683469904d224f3f8f1ee0096f1c5b1b9d.tar.gz STC-modified-1c3e7b683469904d224f3f8f1ee0096f1c5b1b9d.zip | |
Changed c_apply(v, ..) macro to make it more consistent with c_apply_arr(v, ..) and c_foreach (i, ..): v changed to a pointer - not value.
Note: also c_pair(v) is changed correspondingly, so usage with c_apply(v) is unchanged.
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/ccommon.h | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 850bc511..b6023f4b 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -204,17 +204,18 @@ STC_INLINE char* c_strnstrn(const char *s, const char *needle, #define c_apply(v, action, T, ...) do { \
typedef T _c_T; \
- const _c_T _c_arr[] = __VA_ARGS__; \
- for (size_t index = 0; index < c_arraylen(_c_arr); ++index) \
- { const _c_T v = _c_arr[index]; action; } \
+ const _c_T _c_arr[] = __VA_ARGS__, *v = _c_arr, \
+ *_c_end = v + c_arraylen(_c_arr); \
+ while (v != _c_end) { action; ++v; } \
} while (0)
+
#define c_apply_arr(v, action, T, arr, n) do { \
typedef T _c_T; \
- _c_T *_c_arr = arr; \
- for (size_t index = 0, _c_n = n; index < _c_n; ++index) \
- { _c_T *v = _c_arr + index; action; } \
+ _c_T *v = arr, *_c_end = v + (n); \
+ while (v != _c_end) { action; ++v; } \
} while (0)
-#define c_pair(v) (v).first, (v).second
+
+#define c_pair(v) (v)->first, (v)->second
#define c_find_if(C, cnt, it, pred) \
c_find_in(C, C##_begin(&cnt), C##_end(&cnt), it, pred)
|
