diff options
| author | Tyge Løvset <[email protected]> | 2022-07-31 13:03:32 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-07-31 13:03:32 +0200 |
| commit | bc3f6613ba44adcecacbdd106c840e8b6c054e22 (patch) | |
| tree | 9d1d72d8c207592cb25f4892222feaddd22c8b79 | |
| parent | 8a5478f7c14d4c7476d36b137fd7d2c8d95f2c13 (diff) | |
| download | STC-modified-bc3f6613ba44adcecacbdd106c840e8b6c054e22.tar.gz STC-modified-bc3f6613ba44adcecacbdd106c840e8b6c054e22.zip | |
VERSION 3.9: API change in c_forrange() with >= 3 args. csview updates.
| -rw-r--r-- | README.md | 11 | ||||
| -rw-r--r-- | benchmarks/plotbench/cdeq_benchmark.cpp | 4 | ||||
| -rw-r--r-- | benchmarks/plotbench/clist_benchmark.cpp | 4 | ||||
| -rw-r--r-- | benchmarks/plotbench/cmap_benchmark.cpp | 4 | ||||
| -rw-r--r-- | benchmarks/plotbench/cpque_benchmark.cpp | 4 | ||||
| -rw-r--r-- | benchmarks/plotbench/csmap_benchmark.cpp | 4 | ||||
| -rw-r--r-- | benchmarks/plotbench/cvec_benchmark.cpp | 4 | ||||
| -rw-r--r-- | docs/ccommon_api.md | 12 | ||||
| -rw-r--r-- | docs/clist_api.md | 2 | ||||
| -rw-r--r-- | examples/list.c | 2 | ||||
| -rw-r--r-- | examples/stack.c | 4 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 20 |
12 files changed, 39 insertions, 36 deletions
@@ -3,11 +3,14 @@ STC - Smart Template Containers for C ===================================== -News: Version 3.8 released (July 2022) +News: Version 3.9 released (July 2022) --------------------------------------- -- "Officially" added **cregex** - powerful regular expressions. -- Added back **coption** - command line argument parsing. -- Some changes in **cstr** and **csview** API. +- "ccommon API: `c_forrange` with 3 to 5 args swapped 1st <-> 2nd. +- **csview** fully inlined and tokenizer fix +- Version 3.8: + - "Officially" added **cregex** - powerful regular expressions. + - Added back **coption** - command line argument parsing. + - Some changes in **cstr** and **csview** API. - [See detailed changes for version 3](#version-3). Introduction diff --git a/benchmarks/plotbench/cdeq_benchmark.cpp b/benchmarks/plotbench/cdeq_benchmark.cpp index 49db3914..42395778 100644 --- a/benchmarks/plotbench/cdeq_benchmark.cpp +++ b/benchmarks/plotbench/cdeq_benchmark.cpp @@ -109,10 +109,10 @@ Sample test_stc_deque() { int main(int argc, char* argv[]) { Sample std_s[SAMPLES + 1], stc_s[SAMPLES + 1]; - c_forrange (i, int, SAMPLES) { + c_forrange (int, i, SAMPLES) { std_s[i] = test_std_deque(); stc_s[i] = test_stc_deque(); - if (i > 0) c_forrange (j, int, N_TESTS) { + if (i > 0) c_forrange (int, j, N_TESTS) { if (secs(std_s[i].test[j]) < secs(std_s[0].test[j])) std_s[0].test[j] = std_s[i].test[j]; if (secs(stc_s[i].test[j]) < secs(stc_s[0].test[j])) stc_s[0].test[j] = stc_s[i].test[j]; if (stc_s[i].test[j].sum != stc_s[0].test[j].sum) printf("Error in sum: test %d, sample %d\n", i, j); diff --git a/benchmarks/plotbench/clist_benchmark.cpp b/benchmarks/plotbench/clist_benchmark.cpp index ddd1e2f0..fad44ed5 100644 --- a/benchmarks/plotbench/clist_benchmark.cpp +++ b/benchmarks/plotbench/clist_benchmark.cpp @@ -106,10 +106,10 @@ Sample test_stc_forward_list() { int main(int argc, char* argv[]) { Sample std_s[SAMPLES + 1], stc_s[SAMPLES + 1]; - c_forrange (i, int, SAMPLES) { + c_forrange (int, i, SAMPLES) { std_s[i] = test_std_forward_list(); stc_s[i] = test_stc_forward_list(); - if (i > 0) c_forrange (j, int, N_TESTS) { + if (i > 0) c_forrange (int, j, N_TESTS) { if (secs(std_s[i].test[j]) < secs(std_s[0].test[j])) std_s[0].test[j] = std_s[i].test[j]; if (secs(stc_s[i].test[j]) < secs(stc_s[0].test[j])) stc_s[0].test[j] = stc_s[i].test[j]; if (stc_s[i].test[j].sum != stc_s[0].test[j].sum) printf("Error in sum: test %d, sample %d\n", i, j); diff --git a/benchmarks/plotbench/cmap_benchmark.cpp b/benchmarks/plotbench/cmap_benchmark.cpp index cf20c927..b73f6bd1 100644 --- a/benchmarks/plotbench/cmap_benchmark.cpp +++ b/benchmarks/plotbench/cmap_benchmark.cpp @@ -113,10 +113,10 @@ Sample test_stc_unordered_map() { int main(int argc, char* argv[]) { Sample std_s[SAMPLES + 1], stc_s[SAMPLES + 1]; - c_forrange (i, int, SAMPLES) { + c_forrange (int, i, SAMPLES) { std_s[i] = test_std_unordered_map(); stc_s[i] = test_stc_unordered_map(); - if (i > 0) c_forrange (j, int, N_TESTS) { + if (i > 0) c_forrange (int, j, N_TESTS) { if (secs(std_s[i].test[j]) < secs(std_s[0].test[j])) std_s[0].test[j] = std_s[i].test[j]; if (secs(stc_s[i].test[j]) < secs(stc_s[0].test[j])) stc_s[0].test[j] = stc_s[i].test[j]; if (stc_s[i].test[j].sum != stc_s[0].test[j].sum) printf("Error in sum: test %d, sample %d\n", i, j); diff --git a/benchmarks/plotbench/cpque_benchmark.cpp b/benchmarks/plotbench/cpque_benchmark.cpp index ca28082b..9e2f8d18 100644 --- a/benchmarks/plotbench/cpque_benchmark.cpp +++ b/benchmarks/plotbench/cpque_benchmark.cpp @@ -50,12 +50,12 @@ void stc_test() printf("Built priority queue: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC); printf("%g ", *cpque_f_top(&pq)); - c_forrange (i, int, M) { + c_forrange (int, i, M) { cpque_f_pop(&pq); } start = clock(); - c_forrange (i, int, M, N) + c_forrange (int, i, M, N) cpque_f_pop(&pq); printf("\npopped PQ: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC); } diff --git a/benchmarks/plotbench/csmap_benchmark.cpp b/benchmarks/plotbench/csmap_benchmark.cpp index 7e6d62c6..56a0e7d3 100644 --- a/benchmarks/plotbench/csmap_benchmark.cpp +++ b/benchmarks/plotbench/csmap_benchmark.cpp @@ -114,10 +114,10 @@ Sample test_stc_map() { int main(int argc, char* argv[]) { Sample std_s[SAMPLES + 1], stc_s[SAMPLES + 1]; - c_forrange (i, int, SAMPLES) { + c_forrange (int, i, SAMPLES) { std_s[i] = test_std_map(); stc_s[i] = test_stc_map(); - if (i > 0) c_forrange (j, int, N_TESTS) { + if (i > 0) c_forrange (int, j, N_TESTS) { if (secs(std_s[i].test[j]) < secs(std_s[0].test[j])) std_s[0].test[j] = std_s[i].test[j]; if (secs(stc_s[i].test[j]) < secs(stc_s[0].test[j])) stc_s[0].test[j] = stc_s[i].test[j]; if (stc_s[i].test[j].sum != stc_s[0].test[j].sum) printf("Error in sum: test %d, sample %d\n", i, j); diff --git a/benchmarks/plotbench/cvec_benchmark.cpp b/benchmarks/plotbench/cvec_benchmark.cpp index a0faf679..62c4f9c8 100644 --- a/benchmarks/plotbench/cvec_benchmark.cpp +++ b/benchmarks/plotbench/cvec_benchmark.cpp @@ -105,10 +105,10 @@ Sample test_stc_vector() { int main(int argc, char* argv[]) { Sample std_s[SAMPLES + 1] = {{NULL}}, stc_s[SAMPLES + 1] = {{NULL}}; - c_forrange (i, int, SAMPLES) { + c_forrange (int, i, SAMPLES) { std_s[i] = test_std_vector(); stc_s[i] = test_stc_vector(); - if (i > 0) c_forrange (j, int, N_TESTS) { + if (i > 0) c_forrange (int, j, N_TESTS) { if (secs(std_s[i].test[j]) < secs(std_s[0].test[j])) std_s[0].test[j] = std_s[i].test[j]; if (secs(stc_s[i].test[j]) < secs(stc_s[0].test[j])) stc_s[0].test[j] = stc_s[i].test[j]; if (stc_s[i].test[j].sum != stc_s[0].test[j].sum) printf("Error in sum: test %d, sample %d\n", i, j); diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md index 82431d95..1a9fb30e 100644 --- a/docs/ccommon_api.md +++ b/docs/ccommon_api.md @@ -151,19 +151,19 @@ Declare an iterator and specify a range to iterate with a for loop. Like python' | Usage | Python equivalent | |:----------------------------------------------|:-------------------------------------| | `c_forrange (stop)` | `for _ in range(stop):` | -| `c_forrange (i, stop) // IterType = size_t` | `for i in range(stop):` | -| `c_forrange (i, IterType, stop)` | `for i in range(stop):` | -| `c_forrange (i, IterType, start, stop)` | `for i in range(start, stop):` | -| `c_forrange (i, IterType, start, stop, step)` | `for i in range(start, stop, step):` | +| `c_forrange (i, stop) // IntType = size_t` | `for i in range(stop):` | +| `c_forrange (IntType, i, stop)` | `for i in range(stop):` | +| `c_forrange (IntType, i, start, stop)` | `for i in range(start, stop):` | +| `c_forrange (IntType, i, start, stop, step)` | `for i in range(start, stop, step):` | ```c c_forrange (5) printf("x"); // xxxxx c_forrange (i, 5) printf(" %" PRIuMAX "", i); // 0 1 2 3 4 -c_forrange (i, int, -3, 3) printf(" %d", i); +c_forrange (int, i, -3, 3) printf(" %d", i); // -3 -2 -1 0 1 2 -c_forrange (i, int, 30, 0, -5) printf(" %d", i); +c_forrange (int, i, 30, 0, -5) printf(" %d", i); // 30 25 20 15 10 5 ``` diff --git a/docs/clist_api.md b/docs/clist_api.md index 17ee3fa8..e870c8c6 100644 --- a/docs/clist_api.md +++ b/docs/clist_api.md @@ -113,7 +113,7 @@ int main() { 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0 }); - c_forrange (i, int, 1, 10) { + c_forrange (int, i, 1, 10) { if (i & 1) clist_d_push_front(&list, (float) i); else clist_d_push_back(&list, (float) i); } diff --git a/examples/list.c b/examples/list.c index 17ed048d..d76490f8 100644 --- a/examples/list.c +++ b/examples/list.c @@ -18,7 +18,7 @@ int main() { stc64_t rng = stc64_new(1234); stc64_uniformf_t dist = stc64_uniformf_new(100.0f, n); int m = 0; - c_forrange (i, int, n) + c_forrange (int, i, n) clist_fx_push_back(&list, stc64_uniformf(&rng, &dist)), ++m; double sum = 0.0; printf("sumarize %d:\n", m); diff --git a/examples/stack.c b/examples/stack.c index 1991e269..5507c764 100644 --- a/examples/stack.c +++ b/examples/stack.c @@ -14,12 +14,12 @@ int main() { c_auto (cstack_i, stack) c_auto (cstack_c, chars) { - c_forrange (i, int, 101) + c_forrange (int, i, 101) cstack_i_push(&stack, i*i); printf("%d\n", *cstack_i_top(&stack)); - c_forrange (i, int, 90) + c_forrange (int, i, 90) cstack_i_pop(&stack); c_foreach (i, cstack_i, stack) diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 9624909e..449bceec 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -170,19 +170,19 @@ STC_INLINE char* c_strnstrn(const char *s, const char *needle, ; C##_next(&_._it)) #define c_forrange(...) c_MACRO_OVERLOAD(c_forrange, __VA_ARGS__) -#define c_forrange1(stop) for (size_t _c_ii=0, _c_end=stop; _c_ii < _c_end; ++_c_ii) -#define c_forrange2(i, stop) for (size_t i=0, _c_end=stop; i < _c_end; ++i) -#define c_forrange3(i, type, stop) for (type i=0, _c_end=stop; i < _c_end; ++i) -#define c_forrange4(i, type, start, stop) for (type i=start, _c_end=stop; i < _c_end; ++i) -#define c_forrange5(i, type, start, stop, step) \ - for (type i=start, _c_inc=step, _c_end=(stop) - (0 < _c_inc) \ +#define c_forrange1(stop) c_forrange4(size_t, _c_i, 0, stop) +#define c_forrange2(i, stop) c_forrange4(size_t, i, 0, stop) +#define c_forrange3(itype, i, stop) c_forrange4(itype, i, 0, stop) +#define c_forrange4(itype, i, start, stop) for (itype i=start, _c_end=stop; i < _c_end; ++i) +#define c_forrange5(itype, i, start, stop, step) \ + for (itype i=start, _c_inc=step, _c_end=(stop) - (0 < _c_inc) \ ; (i <= _c_end) == (0 < _c_inc); i += _c_inc) #define c_autovar(...) c_MACRO_OVERLOAD(c_autovar, __VA_ARGS__) -#define c_autovar2(declvar, drop) for (declvar, **_c_ii = NULL; !_c_ii; ++_c_ii, drop) -#define c_autovar3(declvar, pred, drop) for (declvar, **_c_ii = NULL; !_c_ii && (pred); ++_c_ii, drop) -#define c_autoscope(init, drop) for (int _c_ii = (init, 0); !_c_ii; ++_c_ii, drop) -#define c_autodefer(...) for (int _c_ii = 0; !_c_ii; ++_c_ii, __VA_ARGS__) +#define c_autovar2(declvar, drop) for (declvar, **_c_i = NULL; !_c_i; ++_c_i, drop) +#define c_autovar3(declvar, pred, drop) for (declvar, **_c_i = NULL; !_c_i && (pred); ++_c_i, drop) +#define c_autoscope(init, drop) for (int _c_i = (init, 0); !_c_i; ++_c_i, drop) +#define c_autodefer(...) 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__) |
