diff options
| author | Tyge Lovset <[email protected]> | 2022-08-11 23:33:14 +0200 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2022-08-11 23:33:14 +0200 |
| commit | f534db7ac4a993a05074868b8840a3a674ac76b4 (patch) | |
| tree | 7b5d6d011f2ec3896ef97b50a05adf797551b1cb /include | |
| parent | 2526ae23267a5381f0564100b2aba73dfc367b58 (diff) | |
| download | STC-modified-f534db7ac4a993a05074868b8840a3a674ac76b4.tar.gz STC-modified-f534db7ac4a993a05074868b8840a3a674ac76b4.zip | |
find_if, find_in changed.
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/ccommon.h | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 8ea58314..a4ae28aa 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -219,16 +219,19 @@ STC_INLINE char* c_strnstrn(const char *s, const char *needle, #define c_pair(v) (v)->first, (v)->second #define c_drop(C, ...) do { c_forarray_p(C*, _p, {__VA_ARGS__}) C##_drop(*_p); } while(0) -#define c_find_if(C, cnt, it, pred) \ - c_find_in(C, C##_begin(&cnt), C##_end(&cnt), it, pred) +// it.ref == NULL when not found: +#define c_find_if(it, C, cnt, pred) do { \ + size_t index = 0; \ + for (it = C##_begin(&cnt); it.ref && !(pred); C##_next(&it)) \ + ++index; \ +} while (0) -// NB: it.ref == NULL when not found, not end.ref: -#define c_find_in(C, start, end, it, pred) do { \ +#define c_find_in(it, C, start, end, pred) do { \ size_t index = 0; \ - C##_iter _end = end; \ - for (it = start; it.ref != _end.ref && !(pred); C##_next(&it)) \ + const C##_value* _endref = (end).ref; \ + for (it = start; it.ref != _endref && !(pred); C##_next(&it)) \ ++index; \ - if (it.ref == _end.ref) it.ref = NULL; \ + if (it.ref == _endref) it.ref = NULL; \ } while (0) #endif // CCOMMON_H_INCLUDED |
