diff options
| author | Tyge Løvset <[email protected]> | 2022-09-26 08:08:47 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-09-26 08:08:47 +0200 |
| commit | ca01dd726e2ed8f8b69f8ff08855e80f4eea7247 (patch) | |
| tree | 0ce1594c39d18a93212f066fd8c3c2477fc6f22b /include/stc | |
| parent | ad5be4349232bbba96c0974bc2693ec7331c4b12 (diff) | |
| download | STC-modified-ca01dd726e2ed8f8b69f8ff08855e80f4eea7247.tar.gz STC-modified-ca01dd726e2ed8f8b69f8ff08855e80f4eea7247.zip | |
DEPRECATED: c_forrange(): replaced with c_forloop(). This uses 'long long' as iter type, i.e. "%lld" printf format.
crange_from() renamed to crange_make().
More docs.
Diffstat (limited to 'include/stc')
| -rw-r--r-- | include/stc/cbits.h | 4 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 21 |
2 files changed, 17 insertions, 8 deletions
diff --git a/include/stc/cbits.h b/include/stc/cbits.h index 06871934..fcb5808d 100644 --- a/include/stc/cbits.h +++ b/include/stc/cbits.h @@ -33,7 +33,7 @@ int main() { cbits_resize(&bset, 43, false); printf("%4zu: ", cbits_size(&bset)); - c_forrange (i, cbits_size(&bset)) + c_forloop (i, cbits_size(&bset)) printf("%d", cbits_at(&bset, i)); puts(""); cbits_set(&bset, 28); @@ -43,7 +43,7 @@ int main() { cbits_set_value(&bset, 99, false); printf("%4zu: ", cbits_size(&bset)); - c_forrange (i, cbits_size(&bset)) + c_forloop (i, cbits_size(&bset)) printf("%d", cbits_at(&bset, i)); puts(""); } diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 2b3cfd76..70d829ff 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -193,6 +193,7 @@ STC_INLINE char* c_strnstrn(const char *s, const char *needle, ; _._it.ref && (_.key = &_._it.ref->first, _.val = &_._it.ref->second) \ ; C##_next(&_._it)) +// [deprecated]: #define c_forrange(...) c_MACRO_OVERLOAD(c_forrange, __VA_ARGS__) #define c_forrange1(stop) c_forrange4(_c_i, size_t, 0, stop) #define c_forrange2(i, stop) c_forrange4(i, size_t, 0, stop) @@ -202,16 +203,24 @@ STC_INLINE char* c_strnstrn(const char *s, const char *needle, #define c_forrange5(i, itype, start, stop, step) \ for (itype i=start, _inc=step, _end=(stop) - (_inc > 0) \ ; (_inc > 0) ^ (i > _end); i += _inc) +// [new]: +#define c_forloop(...) c_MACRO_OVERLOAD(c_forloop, __VA_ARGS__) +#define c_forloop1(stop) for (crange_value _i=0, _end=stop; _i<_end; ++_i) +#define c_forloop2(i, stop) c_forloop4(i, 0, stop, 1) +#define c_forloop3(i, start, stop) c_forloop4(i, start, stop, 1) +#define c_forloop4(i, start, stop, step) \ + for (crange_value i=start, _inc=step, _end=(stop) - (_inc > 0) \ + ; (_inc > 0) ^ (i > _end); i += _inc) typedef long long crange_value; struct {crange_value val, end, step; } typedef crange; struct {crange_value *ref, end, step; } typedef crange_iter; -#define crange_init() crange_from3(0, INTMAX_MAX, 1) -#define crange_from(...) c_MACRO_OVERLOAD(crange_from, __VA_ARGS__) -#define crange_from1(start) crange_from3(start, INTMAX_MAX, 1) -#define crange_from2(start, end) crange_from3(start, end, 1) -STC_INLINE crange crange_from3(crange_value start, crange_value finish, crange_value step) - { crange r = {start, finish - (step > 0), step}; return r; } +#define crange_init() crange_make3(0, INTMAX_MAX, 1) +#define crange_make(...) c_MACRO_OVERLOAD(crange_make, __VA_ARGS__) +#define crange_make1(stop) crange_make3(0, stop, 1) +#define crange_make2(start, stop) crange_make3(start, stop, 1) +STC_INLINE crange crange_make3(crange_value start, crange_value stop, crange_value step) + { crange r = {start, stop - (step > 0), step}; return r; } STC_INLINE crange_iter crange_begin(crange* self) { crange_iter it = {&self->val, self->end, self->step}; return it; } STC_INLINE crange_iter crange_end(crange* self) |
