summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-02-08 16:16:49 +0100
committerTyge Løvset <[email protected]>2023-02-08 17:18:24 +0100
commitc4441f5fc665194fbd7a894a67a64a08c3beac42 (patch)
tree82f231b6e8fcb75625166f98aa785baaa265a3d6
parent673dd5319a488d4b702b94dd9aeda4e497ae4fbc (diff)
downloadSTC-modified-c4441f5fc665194fbd7a894a67a64a08c3beac42.tar.gz
STC-modified-c4441f5fc665194fbd7a894a67a64a08c3beac42.zip
Changed to use lowercase flow-control macros in examples (uppercase will still be supported). Improved many examples to use c_make() to init containers.
-rw-r--r--README.md69
-rw-r--r--docs/carc_api.md16
-rw-r--r--docs/cbox_api.md15
-rw-r--r--docs/ccommon_api.md132
-rw-r--r--docs/cdeq_api.md8
-rw-r--r--docs/clist_api.md30
-rw-r--r--docs/cmap_api.md32
-rw-r--r--docs/cpque_api.md8
-rw-r--r--docs/cqueue_api.md6
-rw-r--r--docs/crandom_api.md4
-rw-r--r--docs/cregex_api.md10
-rw-r--r--docs/cset_api.md17
-rw-r--r--docs/csmap_api.md24
-rw-r--r--docs/cspan_api.md22
-rw-r--r--docs/csset_api.md15
-rw-r--r--docs/cstr_api.md2
-rw-r--r--docs/csview_api.md16
-rw-r--r--docs/cvec_api.md12
-rw-r--r--include/stc/algo/crange.h4
-rw-r--r--include/stc/algo/filter.h23
-rw-r--r--include/stc/cbits.h6
-rw-r--r--include/stc/cbox.h2
-rw-r--r--include/stc/ccommon.h54
-rw-r--r--include/stc/clist.h10
-rw-r--r--include/stc/cmap.h4
-rw-r--r--include/stc/cqueue.h2
-rw-r--r--include/stc/cregex.h2
-rw-r--r--include/stc/cset.h2
-rw-r--r--include/stc/csmap.h4
-rw-r--r--include/stc/cspan.h4
-rw-r--r--include/stc/csset.h2
-rw-r--r--include/stc/csview.h6
-rw-r--r--include/stc/priv/altnames.h30
-rw-r--r--misc/benchmarks/misc/cbits_benchmark.cpp12
-rw-r--r--misc/benchmarks/misc/rust_cmap.c10
-rw-r--r--misc/benchmarks/misc/string_bench_STC.cpp32
-rw-r--r--misc/benchmarks/misc/string_bench_STD.cpp4
-rw-r--r--misc/benchmarks/picobench/picobench_cmap.cpp38
-rw-r--r--misc/benchmarks/picobench/picobench_csmap.cpp44
-rw-r--r--misc/benchmarks/plotbench/cdeq_benchmark.cpp38
-rw-r--r--misc/benchmarks/plotbench/clist_benchmark.cpp34
-rw-r--r--misc/benchmarks/plotbench/cmap_benchmark.cpp38
-rw-r--r--misc/benchmarks/plotbench/cpque_benchmark.cpp12
-rw-r--r--misc/benchmarks/plotbench/csmap_benchmark.cpp38
-rw-r--r--misc/benchmarks/plotbench/cvec_benchmark.cpp30
-rw-r--r--misc/benchmarks/shootout_hashmaps.cpp2
-rw-r--r--misc/examples/arc_containers.c12
-rw-r--r--misc/examples/arc_demo.c16
-rw-r--r--misc/examples/arcvec_erase.c11
-rw-r--r--misc/examples/astar.c12
-rw-r--r--misc/examples/birthday.c12
-rw-r--r--misc/examples/bits.c16
-rw-r--r--misc/examples/bits2.c6
-rw-r--r--misc/examples/books.c6
-rw-r--r--misc/examples/box.c8
-rw-r--r--misc/examples/box2.c6
-rw-r--r--misc/examples/city.c39
-rw-r--r--misc/examples/complex.c2
-rw-r--r--misc/examples/convert.c22
-rw-r--r--misc/examples/csmap_erase.c14
-rw-r--r--misc/examples/csmap_find.c11
-rw-r--r--misc/examples/csmap_insert.c25
-rw-r--r--misc/examples/csset_erase.c13
-rw-r--r--misc/examples/cstr_match.c2
-rw-r--r--misc/examples/demos.c24
-rw-r--r--misc/examples/forfilter.c28
-rw-r--r--misc/examples/forloops.c34
-rw-r--r--misc/examples/functor.c10
-rw-r--r--misc/examples/gauss1.c12
-rw-r--r--misc/examples/gauss2.c8
-rw-r--r--misc/examples/hashmap.c4
-rw-r--r--misc/examples/inits.c32
-rw-r--r--misc/examples/intrusive.c12
-rw-r--r--misc/examples/list.c18
-rw-r--r--misc/examples/list_erase.c9
-rw-r--r--misc/examples/list_splice.c11
-rw-r--r--misc/examples/lower_bound.c16
-rw-r--r--misc/examples/mapmap.c8
-rw-r--r--misc/examples/mmap.c12
-rw-r--r--misc/examples/multidim.c8
-rw-r--r--misc/examples/multimap.c8
-rw-r--r--misc/examples/music_arc.c12
-rw-r--r--misc/examples/new_deq.c10
-rw-r--r--misc/examples/new_list.c16
-rw-r--r--misc/examples/new_map.c12
-rw-r--r--misc/examples/new_pque.c46
-rw-r--r--misc/examples/new_queue.c6
-rw-r--r--misc/examples/new_smap.c20
-rw-r--r--misc/examples/new_sptr.c6
-rw-r--r--misc/examples/new_vec.c10
-rw-r--r--misc/examples/person_arc.c10
-rw-r--r--misc/examples/phonebook.c18
-rw-r--r--misc/examples/prime.c6
-rw-r--r--misc/examples/printspan.c14
-rw-r--r--misc/examples/priority.c10
-rw-r--r--misc/examples/queue.c6
-rw-r--r--misc/examples/random.c6
-rw-r--r--misc/examples/rawptr_elements.c8
-rw-r--r--misc/examples/read.c8
-rw-r--r--misc/examples/regex1.c4
-rw-r--r--misc/examples/regex2.c8
-rw-r--r--misc/examples/regex_match.c10
-rw-r--r--misc/examples/regex_replace.c6
-rw-r--r--misc/examples/replace.c2
-rw-r--r--misc/examples/shape.c10
-rw-r--r--misc/examples/sidebyside.cpp10
-rw-r--r--misc/examples/sorted_map.c12
-rw-r--r--misc/examples/splitstr.c10
-rw-r--r--misc/examples/sso_map.c4
-rw-r--r--misc/examples/stack.c10
-rw-r--r--misc/examples/sview_split.c2
-rw-r--r--misc/examples/unordered_set.c4
-rw-r--r--misc/examples/utf8replace_c.c8
-rw-r--r--misc/examples/vikings.c4
-rw-r--r--misc/examples/words.c12
-rw-r--r--misc/tests/cregex_test.c18
-rw-r--r--misc/tests/cspan_test.c18
-rw-r--r--src/checkauto.l40
118 files changed, 881 insertions, 947 deletions
diff --git a/README.md b/README.md
index aea23a9e..341a8a9d 100644
--- a/README.md
+++ b/README.md
@@ -3,13 +3,14 @@
STC - Smart Template Containers for C
=====================================
-News: Version 4.1 RC2 (Feb 2023)
+News: Version 4.1 RC3 (Feb 2023)
------------------------------------------------
Major changes:
-- Signed sizes and indices for all containers. See C++ Core Guidelines by Stroustrup/Sutter: [ES.100](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es100-dont-mix-signed-and-unsigned-arithmetic), [ES.102](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es102-use-signed-types-for-arithmetic), [ES.106](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es106-dont-try-to-avoid-negative-values-by-using-unsigned), and [ES.107](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es107-dont-use-unsigned-for-subscripts-prefer-gslindex).
- A new exciting [**cspan**](docs/cspan_api.md) single/multi-dimensional array view (with numpy-like slicing).
-- Updates on cregex with several new unicode character classes.
-- Uppercase flow-control macros (ccommon.h). Lowercase macros are [still supported](include/stc/priv/altnames.h).
+- Signed sizes and indices for all containers. See C++ Core Guidelines by Stroustrup/Sutter: [ES.100](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es100-dont-mix-signed-and-unsigned-arithmetic), [ES.102](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es102-use-signed-types-for-arithmetic), [ES.106](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es106-dont-try-to-avoid-negative-values-by-using-unsigned), and [ES.107](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es107-dont-use-unsigned-for-subscripts-prefer-gslindex).
+- Customizable allocator [per templated container type](https://github.com/tylov/STC/discussions/44#discussioncomment-4891925).
+- Updates on cregex with several [new unicode character classes](docs/cregex_api.md#regex-cheatsheet).
+- Uppercase flow-control macro names in ccommon.h [supported as alternative](include/stc/priv/altnames.h).
- Some API changes in cregex and cstr.
- [Previous changes for version 4](#version-4).
@@ -85,8 +86,8 @@ Finally, destruction of the lookup key (i.e. string literal) after usage is not
is convenient in C. A great ergonomic feature is that the alternative lookup type can also be used for adding
entries into containers through using the *emplace*-functions. E.g. `MyCStrVec_emplace_back(&vec, "Hello")`.
3. ***Standardized container iterators***. All container can be iterated the same way, and uses the
-same element access syntax. E.g. `c_FOREACH (it, IntContainer, container) printf(" %d", *it.ref);` will work for
-every type of container defined as `IntContainer` with `int` elements. Also the form `c_FOREACH (it, IntContainer, it1, it2)`
+same element access syntax. E.g. `c_foreach (it, IntContainer, container) printf(" %d", *it.ref);` will work for
+every type of container defined as `IntContainer` with `int` elements. Also the form `c_foreach (it, IntContainer, it1, it2)`
may be used to iterate from `it1` up to `it2`.
Performance
@@ -125,19 +126,19 @@ int main(void)
FVec_drop(&vec); // cleanup memory
}
```
-Below is an alternative way to write this code with STC. It uses the generic flow control macros c_AUTO and c_FOREACH,
+Below is an alternative way to write this code with STC. It uses the generic flow control macros c_auto and c_foreach,
and the function macro *c_make()*. This simplifies the code and makes it less prone to errors, while maintaining readability:
```c
int main()
{
- c_AUTO (FVec, vec) // RAII: define vec, init() and drop() all-in-one syntax.
+ c_auto (FVec, vec) // RAII: define vec, init() and drop() all-in-one syntax.
{
vec = c_make(FVec, {10.f, 20.f, 30.f}); // Initialize with a list of floats.
- c_FOREACH (i, FVec, vec) // Iterate elements of the container.
+ c_foreach (i, FVec, vec) // Iterate elements of the container.
printf(" %g", *i.ref); // i.ref is a pointer to the current element.
}
- // vec is "dropped" at end of c_AUTO scope
+ // vec is "dropped" at end of c_auto scope
}
```
For user defined struct elements, `i_cmp` compare function should be defined, as the default `<` and `==`
@@ -199,12 +200,12 @@ int Point_cmp(const struct Point* a, const struct Point* b) {
int main(void)
{
/* Define six containers with automatic call of init and drop (destruction after scope exit) */
- c_AUTO (cset_int, set)
- c_AUTO (cvec_pnt, vec)
- c_AUTO (cdeq_int, deq)
- c_AUTO (clist_int, lst)
- c_AUTO (cstack_int, stk)
- c_AUTO (csmap_int, map)
+ c_auto (cset_int, set)
+ c_auto (cvec_pnt, vec)
+ c_auto (cdeq_int, deq)
+ c_auto (clist_int, lst)
+ c_auto (cstack_int, stk)
+ c_auto (csmap_int, map)
{
int nums[4] = {10, 20, 30, 40};
struct Point pts[4] = { {10, 1}, {20, 2}, {30, 3}, {40, 4} };
@@ -240,27 +241,27 @@ int main(void)
printf("After erasing the elements found:");
printf("\n set:");
- c_FOREACH (i, cset_int, set)
+ c_foreach (i, cset_int, set)
printf(" %d", *i.ref);
printf("\n vec:");
- c_FOREACH (i, cvec_pnt, vec)
+ c_foreach (i, cvec_pnt, vec)
printf(" (%g, %g)", i.ref->x, i.ref->y);
printf("\n deq:");
- c_FOREACH (i, cdeq_int, deq)
+ c_foreach (i, cdeq_int, deq)
printf(" %d", *i.ref);
printf("\n lst:");
- c_FOREACH (i, clist_int, lst)
+ c_foreach (i, clist_int, lst)
printf(" %d", *i.ref);
printf("\n stk:");
- c_FOREACH (i, cstack_int, stk)
+ c_foreach (i, cstack_int, stk)
printf(" %d", *i.ref);
printf("\n map:");
- c_FOREACH (i, csmap_int, map)
+ c_foreach (i, csmap_int, map)
printf(" [%d: %d]", i.ref->first, i.ref->second);
}
}
@@ -397,8 +398,8 @@ and non-emplace methods:
#define i_val_str // special macro to enable container of cstr
#include <stc/cvec.h> // vector of string (cstr)
...
-c_AUTO (cvec_str, vec) // declare and call cvec_str_init() and defer cvec_str_drop(&vec)
-c_WITH (cstr s = cstr_lit("a string literal"), cstr_drop(&s))
+c_auto (cvec_str, vec) // declare and call cvec_str_init() and defer cvec_str_drop(&vec)
+c_with (cstr s = cstr_lit("a string literal"), cstr_drop(&s))
{
const char* hello = "Hello";
cvec_str_push_back(&vec, cstr_from(hello); // construct and add string from const char*
@@ -494,16 +495,16 @@ Memory efficiency
## API changes summary V4.0
- Added **cregex** with documentation - powerful regular expressions.
-- Added: `c_FORFILTER`: container iteration with "piped" filtering using && operator. 4 built-in filters.
-- Added: `c_FORWHILE`: *c_FOREACH* container iteration with extra predicate.
-- Added: **crange**: number generator type, which can be iterated (e.g. with *c_FORFILTER*).
+- Added: `c_forfilter`: container iteration with "piped" filtering using && operator. 4 built-in filters.
+- Added: `c_forwhile`: *c_foreach* container iteration with extra predicate.
+- Added: **crange**: number generator type, which can be iterated (e.g. with *c_forfilter*).
- Added back **coption** - command line argument parsing.
- New + renamed loop iteration/scope macros:
- - `c_FORLIST`: macro replacing `c_forarray` and `c_apply`. Iterate a compound literal list.
- - `c_FORRANGE`: macro replacing `c_FORRANGE`. Iterate a `long long` type number sequence.
- - `c_WITH`: macro renamed from `c_autovar`. Like Python's **with** statement.
- - `c_SCOPE`: macro renamed from `c_autoscope`.
- - `c_DEFER`: macro renamed from `c_autodefer`. Resembles Go's and Zig's **defer**.
+ - `c_forlist`: macro replacing `c_forarray` and `c_apply`. Iterate a compound literal list.
+ - `c_forrange`: macro replacing `c_forrange`. Iterate a `long long` type number sequence.
+ - `c_with`: macro renamed from `c_autovar`. Like Python's **with** statement.
+ - `c_scope`: macro renamed from `c_autoscope`.
+ - `c_defer`: macro renamed from `c_autodefer`. Resembles Go's and Zig's **defer**.
- Updated **cstr**, now always takes self as pointer, like all containers except csview.
- Updated **cvec**, **cdeq**, changed `*_range*` function names.
@@ -551,8 +552,8 @@ Memory efficiency
- Renamed: *c_default_fromraw()* to `c_default_from()`.
- Changed: the [**c_apply**](docs/ccommon_api.md) macros API.
- Replaced: *csview_first_token()* and *csview_next_token()* with one function: `csview_token()`.
-- Added: **checkauto** tool for checking that c-source files uses `c_AUTO*` macros correctly.
+- Added: **checkauto** tool for checking that c-source files uses `c_auto*` macros correctly.
- Added: general `i_keyclass` / `i_valclass` template parameters which auto-binds template functions.
- Added: `i_opt` template parameter: compile-time options: `c_no_cmp`, `c_no_clone`, `c_no_atomic`, `c_is_forward`; may be combined with `|`
- Added: [**cbox**](docs/cbox_api.md) type: smart pointer, similar to [Rust Box](https://doc.rust-lang.org/rust-by-example/std/box.html) and [std::unique_ptr](https://en.cppreference.com/w/cpp/memory/unique_ptr).
-- Added: [**c_FORPAIR**](docs/ccommon_api.md) macro: for-loop with "structured binding"
+- Added: [**c_forpair**](docs/ccommon_api.md) macro: for-loop with "structured binding"
diff --git a/docs/carc_api.md b/docs/carc_api.md
index f91975a7..cc6c9c32 100644
--- a/docs/carc_api.md
+++ b/docs/carc_api.md
@@ -98,24 +98,24 @@ bool carc_X_value_eq(const i_val* x, const i_val* y);
int main()
{
- c_AUTO (Stack, s1, s2) // RAII
+ c_auto (Stack, s1, s2) // RAII
{
// POPULATE s1 with shared pointers to Map:
Map *map;
map = Stack_push(&s1, Arc_make(Map_init()))->get; // push empty map to s1.
- c_FORLIST (i, Map_raw, { {"Joey", 1990}, {"Mary", 1995}, {"Joanna", 1992} }) {
+ c_forlist (i, Map_raw, { {"Joey", 1990}, {"Mary", 1995}, {"Joanna", 1992} }) {
Map_emplace(map, c_PAIR(i.ref)); // populate it.
}
map = Stack_push(&s1, Arc_make(Map_init()))->get;
- c_FORLIST (i, Map_raw, { {"Rosanna", 2001}, {"Brad", 1999}, {"Jack", 1980} }) {
+ c_forlist (i, Map_raw, { {"Rosanna", 2001}, {"Brad", 1999}, {"Jack", 1980} }) {
Map_emplace(map, c_PAIR(i.ref));
}
// POPULATE s2:
map = Stack_push(&s2, Arc_make(Map_init()))->get;
- c_FORLIST (i, Map_raw, { {"Steve", 1979}, {"Rick", 1974}, {"Tracy", 2003} }) {
+ c_forlist (i, Map_raw, { {"Steve", 1979}, {"Rick", 1974}, {"Tracy", 2003} }) {
Map_emplace(map, c_PAIR(i.ref));
}
@@ -134,15 +134,15 @@ int main()
Map_emplace_or_assign(s1.data[1].get, "Shared", 2022);
puts("S1");
- c_FOREACH (i, Stack, s1) {
- c_FORPAIR (name, year, Map, *i.ref->get)
+ c_foreach (i, Stack, s1) {
+ c_forpair (name, year, Map, *i.ref->get)
printf(" %s:%d", cstr_str(_.name), *_.year);
puts("");
}
puts("S2");
- c_FOREACH (i, Stack, s2) {
- c_FORPAIR (name, year, Map, *i.ref->get)
+ c_foreach (i, Stack, s2) {
+ c_forpair (name, year, Map, *i.ref->get)
printf(" %s:%d", cstr_str(_.name), *_.year);
puts("");
}
diff --git a/docs/cbox_api.md b/docs/cbox_api.md
index 4430b9f8..eff0fbc1 100644
--- a/docs/cbox_api.md
+++ b/docs/cbox_api.md
@@ -92,18 +92,17 @@ void int_drop(int* x) {
int main()
{
- c_AUTO (IVec, vec) // declare and init vec, call drop at scope exit
- c_AUTO (ISet, set) // similar
+ c_auto (IVec, vec) // declare and init vec, call drop at scope exit
+ c_auto (ISet, set) // similar
{
- c_FORLIST (i, int, {2021, 2012, 2022, 2015})
- IVec_emplace(&vec, *i.ref); // same as: IVec_push(&vec, IBox_from(*i.ref));
+ vec = c_make(Vec, {2021, 2012, 2022, 2015});
printf("vec:");
- c_FOREACH (i, IVec, vec)
+ c_foreach (i, IVec, vec)
printf(" %d", *i.ref->get);
// add odd numbers from vec to set
- c_FOREACH (i, IVec, vec)
+ c_foreach (i, IVec, vec)
if (*i.ref->get & 1)
ISet_insert(&set, IBox_clone(*i.ref));
@@ -112,11 +111,11 @@ int main()
IVec_pop(&vec);
printf("\nvec:");
- c_FOREACH (i, IVec, vec)
+ c_foreach (i, IVec, vec)
printf(" %d", *i.ref->get);
printf("\nset:");
- c_FOREACH (i, ISet, set)
+ c_foreach (i, ISet, set)
printf(" %d", *i.ref->get);
}
}
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md
index b0bd18e4..04af832b 100644
--- a/docs/ccommon_api.md
+++ b/docs/ccommon_api.md
@@ -3,27 +3,27 @@
The following macros are recommended to use, and they safe/have no side-effects.
## Scope macros (RAII)
-### c_AUTO, c_WITH, c_SCOPE, c_DEFER
+### c_auto, c_with, c_scope, c_defer
General ***defer*** mechanics for resource acquisition. These macros allows you to specify the
freeing of the resources at the point where the acquisition takes place.
-The **checkauto** utility described below, ensures that the `c_AUTO*` macros are used correctly.
+The **checkauto** utility described below, ensures that the `c_auto*` macros are used correctly.
| Usage | Description |
|:---------------------------------------|:----------------------------------------------------------|
-| `c_WITH (Type var=init, drop)` | Declare `var`. Defer `drop...` to end of scope |
-| `c_WITH (Type var=init, pred, drop)` | Adds a predicate in order to exit early if init failed |
-| `c_AUTO (Type, var1,...,var4)` | `c_WITH (Type var1=Type_init(), Type_drop(&var1))` ... |
-| `c_SCOPE (init, drop)` | Execute `init` and defer `drop` to end of scope |
-| `c_DEFER (drop...)` | Defer `drop...` to end of scope |
+| `c_with (Type var=init, drop)` | Declare `var`. Defer `drop...` to end of scope |
+| `c_with (Type var=init, pred, drop)` | Adds a predicate in order to exit early if init failed |
+| `c_auto (Type, var1,...,var4)` | `c_with (Type var1=Type_init(), Type_drop(&var1))` ... |
+| `c_scope (init, drop)` | Execute `init` and defer `drop` to end of scope |
+| `c_defer (drop...)` | Defer `drop...` to end of scope |
| `continue` | Exit a block above without memory leaks |
-For multiple variables, use either multiple **c_WITH** in sequence, or declare variable outside
-scope and use **c_SCOPE**. For convenience, **c_AUTO** support up to 4 variables.
+For multiple variables, use either multiple **c_with** in sequence, or declare variable outside
+scope and use **c_scope**. For convenience, **c_auto** support up to 4 variables.
```c
-// `c_WITH` is similar to python `with`: it declares and can drop a variable after going out of scope.
+// `c_with` is similar to python `with`: it declares and can drop a variable after going out of scope.
bool ok = false;
-c_WITH (uint8_t* buf = malloc(BUF_SIZE), buf != NULL, free(buf))
-c_WITH (FILE* fp = fopen(fname, "rb"), fp != NULL, fclose(fp))
+c_with (uint8_t* buf = malloc(BUF_SIZE), buf != NULL, free(buf))
+c_with (FILE* fp = fopen(fname, "rb"), fp != NULL, fclose(fp))
{
int n = fread(buf, 1, BUF_SIZE, fp);
if (n <= 0) continue; // auto cleanup! NB do not break or return here.
@@ -32,8 +32,8 @@ c_WITH (FILE* fp = fopen(fname, "rb"), fp != NULL, fclose(fp))
}
return ok;
-// `c_AUTO` automatically initialize and destruct up to 4 variables, like c_WITH.
-c_AUTO (cstr, s1, s2)
+// `c_auto` automatically initialize and destruct up to 4 variables, like c_with.
+c_auto (cstr, s1, s2)
{
cstr_append(&s1, "Hello");
cstr_append(&s1, " world");
@@ -44,22 +44,22 @@ c_AUTO (cstr, s1, s2)
printf("%s %s\n", cstr_str(&s1), cstr_str(&s2));
}
-c_WITH (cstr str = cstr_lit("Hello"), cstr_drop(&str))
+c_with (cstr str = cstr_lit("Hello"), cstr_drop(&str))
{
cstr_append(&str, " world");
printf("%s\n", cstr_str(&str));
}
-// `c_SCOPE` is like `c_WITH` but works with an already declared variable.
+// `c_scope` is like `c_with` but works with an already declared variable.
static pthread_mutex_t mut;
-c_SCOPE (pthread_mutex_lock(&mut), pthread_mutex_unlock(&mut))
+c_scope (pthread_mutex_lock(&mut), pthread_mutex_unlock(&mut))
{
/* Do syncronized work. */
}
-// `c_DEFER` executes the expressions when leaving scope. Prefer c_WITH or c_SCOPE.
+// `c_defer` executes the expressions when leaving scope. Prefer c_with or c_scope.
cstr s1 = cstr_lit("Hello"), s2 = cstr_lit("world");
-c_DEFER (cstr_drop(&s1), cstr_drop(&s2))
+c_defer (cstr_drop(&s1), cstr_drop(&s2))
{
printf("%s %s\n", cstr_str(&s1), cstr_str(&s2));
}
@@ -77,8 +77,8 @@ cvec_str readFile(const char* name)
{
cvec_str vec = cvec_str_init(); // returned
- c_WITH (FILE* fp = fopen(name, "r"), fp != NULL, fclose(fp))
- c_WITH (cstr line = cstr_NULL, cstr_drop(&line))
+ c_with (FILE* fp = fopen(name, "r"), fp != NULL, fclose(fp))
+ c_with (cstr line = cstr_NULL, cstr_drop(&line))
while (cstr_getline(&line, fp))
cvec_str_emplace_back(&vec, cstr_str(&line));
return vec;
@@ -86,30 +86,30 @@ cvec_str readFile(const char* name)
int main()
{
- c_WITH (cvec_str x = readFile(__FILE__), cvec_str_drop(&x))
- c_FOREACH (i, cvec_str, x)
+ c_with (cvec_str x = readFile(__FILE__), cvec_str_drop(&x))
+ c_foreach (i, cvec_str, x)
printf("%s\n", cstr_str(i.ref));
}
```
### The **checkauto** utility program (for RAII)
-The **checkauto** program will check the source code for any misuses of the `c_AUTO*` macros which
-may lead to resource leakages. The `c_AUTO*`- macros are implemented as one-time executed **for-loops**,
+The **checkauto** program will check the source code for any misuses of the `c_auto*` macros which
+may lead to resource leakages. The `c_auto*`- macros are implemented as one-time executed **for-loops**,
so any `return` or `break` appearing within such a block will lead to resource leaks, as it will disable
the cleanup/drop method to be called. A `break` may originally be intended to break a loop or switch
-outside the `c_AUTO` scope.
+outside the `c_auto` scope.
-NOTE: One must always make sure to unwind temporary allocated resources before a `return` in C. However, by using `c_AUTO*`-macros,
+NOTE: One must always make sure to unwind temporary allocated resources before a `return` in C. However, by using `c_auto*`-macros,
- it is much easier to automatically detect misplaced return/break between resource acquisition and destruction.
- it prevents forgetting to call the destructor at the end.
The **checkauto** utility will report any misusages. The following example shows how to correctly break/return
-from a `c_AUTO` scope:
+from a `c_auto` scope:
```c
int flag = 0;
for (int i = 0; i<n; ++i) {
- c_AUTO (cstr, text)
- c_AUTO (List, list)
+ c_auto (cstr, text)
+ c_auto (List, list)
{
for (int j = 0; j<m; ++j) {
List_push_back(&list, i*j);
@@ -118,23 +118,23 @@ from a `c_AUTO` scope:
}
// WRONG:
if (cond2())
- break; // checkauto ERROR! break inside c_AUTO.
+ break; // checkauto ERROR! break inside c_auto.
if (cond3())
- return -1; // checkauto ERROR! return inside c_AUTO
+ return -1; // checkauto ERROR! return inside c_auto
// CORRECT:
if (cond2()) {
flag = 1; // flag to break outer for-loop
- continue; // cleanup and leave c_AUTO block
+ continue; // cleanup and leave c_auto block
}
if (cond3()) {
flag = -1; // return -1
- continue; // cleanup and leave c_AUTO block
+ continue; // cleanup and leave c_auto block
}
...
}
- // do the return/break outside of c_AUTO
+ // do the return/break outside of c_auto
if (flag < 0) return flag;
else if (flag > 0) break;
...
@@ -142,33 +142,33 @@ from a `c_AUTO` scope:
```
## Loop abstraction macros
-### c_FORLIST
+### c_forlist
Iterate compound literal array elements. Additional to `i.ref`, you can access `i.data`, `i.size`, and `i.index` of the input list/element.
```c
// apply multiple push_backs
-c_FORLIST (i, int, {1, 2, 3})
+c_forlist (i, int, {1, 2, 3})
cvec_i_push_back(&vec, *i.ref);
// insert in existing map
-c_FORLIST (i, cmap_ii_raw, { {4, 5}, {6, 7} })
+c_forlist (i, cmap_ii_raw, { {4, 5}, {6, 7} })
cmap_ii_insert(&map, i.ref->first, i.ref->second);
// string literals pushed to a stack of cstr:
-c_FORLIST (i, const char*, {"Hello", "crazy", "world"})
+c_forlist (i, const char*, {"Hello", "crazy", "world"})
cstack_str_emplace(&stk, *i.ref);
// reverse the list:
-c_FORLIST (i, int, {1, 2, 3})
+c_forlist (i, int, {1, 2, 3})
cvec_i_push_back(&vec, i.data[i.size - 1 - i.index]);
```
-### c_FOREACH, c_FORPAIR
+### c_foreach, c_forpair
| Usage | Description |
|:-----------------------------------------|:--------------------------------|
-| `c_FOREACH (it, ctype, container)` | Iteratate all elements |
-| `c_FOREACH (it, ctype, it1, it2)` | Iterate the range [it1, it2) |
-| `c_FORPAIR (key, val, ctype, container)` | Iterate with structured binding |
+| `c_foreach (it, ctype, container)` | Iteratate all elements |
+| `c_foreach (it, ctype, it1, it2)` | Iterate the range [it1, it2) |
+| `c_forpair (key, val, ctype, container)` | Iterate with structured binding |
```c
#define i_key int
@@ -176,52 +176,52 @@ c_FORLIST (i, int, {1, 2, 3})
#define i_tag ii
#include <stc/csmap.h>
...
-c_FORLIST (i, csmap_ii_raw, { {23,1}, {3,2}, {7,3}, {5,4}, {12,5} })
+c_forlist (i, csmap_ii_raw, { {23,1}, {3,2}, {7,3}, {5,4}, {12,5} })
csmap_ii_insert(&map, i.ref->first, i.ref->second);
-c_FOREACH (i, csmap_ii, map)
+c_foreach (i, csmap_ii, map)
printf(" %d", i.ref->first);
// 3 5 7 12 23
csmap_ii_iter it = csmap_ii_find(&map, 7);
-c_FOREACH (i, csmap_ii, it, csmap_ii_end(&map))
+c_foreach (i, csmap_ii, it, csmap_ii_end(&map))
printf(" %d", i.ref->first);
// 7 12 23
-c_FORPAIR (id, count, csmap_ii, map)
+c_forpair (id, count, csmap_ii, map)
printf(" (%d %d)", *_.id, *_.count);
// (3 2) (5 4) (7 3) (12 5) (23 1)
```
-### c_FORRANGE
+### c_forrange
Abstraction for iterating sequence of numbers. Like python's **for** *i* **in** *range()* loop.
| Usage | Python equivalent |
|:--------------------------------------------|:-------------------------------------|
-| `c_FORRANGE (stop)` | `for _ in range(stop):` |
-| `c_FORRANGE (i, stop) // i type = long long` | `for i in range(stop):` |
-| `c_FORRANGE (i, start, stop)` | `for i in range(start, stop):` |
-| `c_FORRANGE (i, start, stop, step)` | `for i in range(start, stop, step):` |
+| `c_forrange (stop)` | `for _ in range(stop):` |
+| `c_forrange (i, stop) // i type = long long` | `for i in range(stop):` |
+| `c_forrange (i, start, stop)` | `for i in range(start, stop):` |
+| `c_forrange (i, start, stop, step)` | `for i in range(start, stop, step):` |
```c
-c_FORRANGE (5) printf("x");
+c_forrange (5) printf("x");
// xxxxx
-c_FORRANGE (i, 5) printf(" %lld", i);
+c_forrange (i, 5) printf(" %lld", i);
// 0 1 2 3 4
-c_FORRANGE (i, -3, 3) printf(" %lld", i);
+c_forrange (i, -3, 3) printf(" %lld", i);
// -3 -2 -1 0 1 2
-c_FORRANGE (i, 30, 0, -5) printf(" %lld", i);
+c_forrange (i, 30, 0, -5) printf(" %lld", i);
// 30 25 20 15 10 5
```
-### c_FORWHILE, c_FORFILTER
+### c_forwhile, c_forfilter
Iterate containers with stop-criteria and chained range filtering.
| Usage | Description |
|:----------------------------------------------------|:---------------------------------------|
-| `c_FORWHILE (it, ctype, start, pred)` | Iterate until pred is false |
-| `c_FORFILTER (it, ctype, container, filter)` | Filter out items in chain with && |
-| `c_FORFILTER (it, ctype, container, filter, pred)` | Filter and iterate until pred is false |
+| `c_forwhile (it, ctype, start, pred)` | Iterate until pred is false |
+| `c_forfilter (it, ctype, container, filter)` | Filter out items in chain with && |
+| `c_forfilter (it, ctype, container, filter, pred)` | Filter and iterate until pred is false |
| Built-in filter | Description |
|:----------------------------------|:-------------------------------------|
@@ -244,10 +244,10 @@ bool isPrime(int i) {
#define isOdd(i) ((i) & 1)
int main() {
- c_AUTO (IVec, vec) {
- c_FORRANGE (i, 1000) IVec_push(&vec, 1000000 + i);
+ c_auto (IVec, vec) {
+ c_forrange (i, 1000) IVec_push(&vec, 1000000 + i);
- c_FORFILTER (i, IVec, vec,
+ c_forfilter (i, IVec, vec,
isOdd(*i.ref)
&& c_flt_skip(i, 100) // built-in
&& isPrime(*i.ref)
@@ -302,14 +302,14 @@ void crange_next(crange_iter* it);
// 1. All primes less than 32:
crange r1 = crange_make(3, 32, 2);
printf("2"); // first prime
-c_FORFILTER (i, crange, r1
+c_forfilter (i, crange, r1
, isPrime(*i.ref))
printf(" %lld", *i.ref);
// 2 3 5 7 11 13 17 19 23 29 31
// 2. The 11 first primes:
printf("2");
-c_FORFILTER (i, crange, crange_obj(3, INT64_MAX, 2)
+c_forfilter (i, crange, crange_obj(3, INT64_MAX, 2)
, isPrime(*i.ref)
, c_flt_take(10))
printf(" %lld", *i.ref);
diff --git a/docs/cdeq_api.md b/docs/cdeq_api.md
index 716a608c..fc11fe66 100644
--- a/docs/cdeq_api.md
+++ b/docs/cdeq_api.md
@@ -109,14 +109,14 @@ cdeq_X_value cdeq_X_value_clone(cdeq_X_value val);
int main() {
cdeq_i q = cdeq_i_init();
cdeq_i_push_front(&q, 10);
- c_FOREACH (i, cdeq_i, q)
+ c_foreach (i, cdeq_i, q)
printf(" %d", *i.ref);
puts("");
- c_FORLIST (i, int, {1, 4, 5, 22, 33, 2})
+ c_forlist (i, int, {1, 4, 5, 22, 33, 2})
cdeq_i_push_back(&q, *i.ref)
- c_FOREACH (i, cdeq_i, q)
+ c_foreach (i, cdeq_i, q)
printf(" %d", *i.ref);
puts("");
@@ -125,7 +125,7 @@ int main() {
cdeq_i_push_back(&q, 11);
cdeq_i_push_front(&q, 8);
- c_FOREACH (i, cdeq_i, q)
+ c_foreach (i, cdeq_i, q)
printf(" %d", *i.ref);
puts("");
cdeq_i_drop(&q);
diff --git a/docs/clist_api.md b/docs/clist_api.md
index 29bfd5ff..3e73d42b 100644
--- a/docs/clist_api.md
+++ b/docs/clist_api.md
@@ -119,24 +119,21 @@ Interleave *push_front()* / *push_back()* then *sort()*:
#include <stdio.h>
int main() {
- DList list = DList_init();
+ DList list = c_make(DList, {10., 20., 30., 40., 50., 60., 70., 80., 90.});
- c_FORLIST (i, double, {10., 20., 30., 40., 50., 60., 70., 80., 90.})
- DList_push_back(&list, *i.ref);
-
- c_FORRANGE (i, 1, 10) {
+ c_forrange (i, 1, 10) {
if (i & 1) DList_push_front(&list, (double) i);
else DList_push_back(&list, (double) i);
}
printf("initial: ");
- c_FOREACH (i, DList, list)
+ c_foreach (i, DList, list)
printf(" %g", *i.ref);
DList_sort(&list); // mergesort O(n*log n)
printf("\nsorted: ");
- c_FOREACH (i, DList, list)
+ c_foreach (i, DList, list)
printf(" %g", *i.ref);
DList_drop(&list);
@@ -160,10 +157,7 @@ Use of *erase_at()* and *erase_range()*:
int main ()
{
- clist_i L = clist_i_init();
-
- c_FORLIST (i, int, {10, 20, 30, 40, 50})
- clist_i_push_back(&L, *i.ref);
+ clist_i L = c_make(clist_i, {10, 20, 30, 40, 50});
// 10 20 30 40 50
clist_i_iter it = clist_i_begin(&L); // ^
clist_i_next(&it);
@@ -174,7 +168,7 @@ int main ()
it = clist_i_erase_range(&L, it, end); // 10 30
// ^
printf("mylist contains:");
- c_FOREACH (x, clist_i, L)
+ c_foreach (x, clist_i, L)
printf(" %d", *x.ref);
puts("");
@@ -197,21 +191,19 @@ Splice `[30, 40]` from *L2* into *L1* before `3`:
#include <stdio.h>
int main() {
- c_AUTO (clist_i, L1, L2)
+ c_auto (clist_i, L1, L2)
{
- c_FORLIST (i, int, {1, 2, 3, 4, 5})
- clist_i_push_back(&L1, *i.ref);
- c_FORLIST (i, int, {10, 20, 30, 40, 50})
- clist_i_push_back(&L2, *i.ref);
+ L1 = c_make(clist_i, {1, 2, 3, 4, 5});
+ L2 = c_make(clist_i, {10, 20, 30, 40, 50});
clist_i_iter i = clist_i_advance(clist_i_begin(&L1), 2);
clist_i_iter j1 = clist_i_advance(clist_i_begin(&L2), 2), j2 = clist_i_advance(j1, 2);
clist_i_splice_range(&L1, i, &L2, j1, j2);
- c_FOREACH (i, clist_i, L1)
+ c_foreach (i, clist_i, L1)
printf(" %d", *i.ref); puts("");
- c_FOREACH (i, clist_i, L2)
+ c_foreach (i, clist_i, L2)
printf(" %d", *i.ref); puts("");
}
}
diff --git a/docs/cmap_api.md b/docs/cmap_api.md
index 0b91abc7..263aff10 100644
--- a/docs/cmap_api.md
+++ b/docs/cmap_api.md
@@ -126,16 +126,16 @@ bool c_memcmp_eq(const i_keyraw* a, const i_keyraw* b); // !
int main()
{
// Create an unordered_map of three strings (that map to strings)
- c_AUTO (cmap_str, u)
+ c_auto (cmap_str, u)
{
- c_FORLIST (i, cmap_str_raw, {
+ u = c_make(cmap_str, {
{"RED", "#FF0000"},
{"GREEN", "#00FF00"},
{"BLUE", "#0000FF"}
- }) cmap_str_emplace(&u, c_PAIR(i.ref));
+ });
// Iterate and print keys and values of unordered map
- c_FOREACH (n, cmap_str, u) {
+ c_foreach (n, cmap_str, u) {
printf("Key:[%s] Value:[%s]\n", cstr_str(&n.ref->first), cstr_str(&n.ref->second));
}
@@ -172,9 +172,9 @@ int main()
{
uint32_t col = 0xcc7744ff;
- c_AUTO (cmap_id, idnames)
+ c_auto (cmap_id, idnames)
{
- c_FORLIST (i, cmap_id_raw, { {100, "Red"}, {110, "Blue"} })
+ c_forlist (i, cmap_id_raw, { {100, "Red"}, {110, "Blue"} })
cmap_id_emplace(&idnames, c_PAIR(i.ref));
// replace existing mapped value:
@@ -186,7 +186,7 @@ int main()
// emplace/insert does nothing if key already exist:
cmap_id_emplace(&idnames, 100, "Green");
- c_FOREACH (i, cmap_id, idnames)
+ c_foreach (i, cmap_id, idnames)
printf("%d: %s\n", i.ref->first, cstr_str(&i.ref->second));
}
}
@@ -213,14 +213,14 @@ typedef struct { int x, y, z; } Vec3i;
int main()
{
// Define map with defered destruct
- c_WITH (cmap_vi vecs = cmap_vi_init(), cmap_vi_drop(&vecs))
+ c_with (cmap_vi vecs = cmap_vi_init(), cmap_vi_drop(&vecs))
{
cmap_vi_insert(&vecs, (Vec3i){100, 0, 0}, 1);
cmap_vi_insert(&vecs, (Vec3i){ 0, 100, 0}, 2);
cmap_vi_insert(&vecs, (Vec3i){ 0, 0, 100}, 3);
cmap_vi_insert(&vecs, (Vec3i){100, 100, 100}, 4);
- c_FORPAIR (v3, num, cmap_vi, vecs)
+ c_forpair (v3, num, cmap_vi, vecs)
printf("{ %3d, %3d, %3d }: %d\n", _.v3->x, _.v3->y, _.v3->z, *_.num);
}
}
@@ -246,14 +246,14 @@ typedef struct { int x, y, z; } Vec3i;
int main()
{
- c_AUTO (cmap_iv, vecs) // shorthand for c_WITH with _init(), _drop().
+ c_auto (cmap_iv, vecs) // shorthand for c_with with _init(), _drop().
{
cmap_iv_insert(&vecs, 1, (Vec3i){100, 0, 0});
cmap_iv_insert(&vecs, 2, (Vec3i){ 0, 100, 0});
cmap_iv_insert(&vecs, 3, (Vec3i){ 0, 0, 100});
cmap_iv_insert(&vecs, 4, (Vec3i){100, 100, 100});
- c_FORPAIR (num, v3, cmap_iv, vecs)
+ c_forpair (num, v3, cmap_iv, vecs)
printf("%d: { %3d, %3d, %3d }\n", *_.num, _.v3->x, _.v3->y, _.v3->z);
}
}
@@ -313,20 +313,20 @@ static inline void Viking_drop(Viking* vk) {
int main()
{
// Use a HashMap to store the vikings' health points.
- c_AUTO (Vikings, vikings) // uses Vikings_init(), Vikings_drop()
+ c_auto (Vikings, vikings) // uses Vikings_init(), Vikings_drop()
{
Vikings_insert(&vikings, (Viking){cstr_lit("Einar"), cstr_lit("Norway")}, 25);
Vikings_insert(&vikings, (Viking){cstr_lit("Olaf"), cstr_lit("Denmark")}, 24);
Vikings_insert(&vikings, (Viking){cstr_lit("Harald"), cstr_lit("Iceland")}, 12);
Vikings_insert(&vikings, (Viking){cstr_lit("Einar"), cstr_lit("Denmark")}, 21);
- c_AUTO (Viking, lookup) {
+ c_auto (Viking, lookup) {
lookup = (Viking){cstr_lit("Einar"), cstr_lit("Norway")};
printf("Lookup: Einar of Norway has %d hp\n\n", *Vikings_at(&vikings, lookup));
}
// Print the status of the vikings.
- c_FORPAIR (vik, hp, Vikings, vikings) {
+ c_forpair (vik, hp, Vikings, vikings) {
printf("%s of %s has %d hp\n", cstr_str(&_.vik->name), cstr_str(&_.vik->country), *_.hp);
}
}
@@ -396,7 +396,7 @@ static inline RViking Viking_toraw(const Viking* vp) {
int main()
{
- c_AUTO (Vikings, vikings)
+ c_auto (Vikings, vikings)
{
Vikings_emplace(&vikings, (RViking){"Einar", "Norway"}, 20);
Vikings_emplace(&vikings, (RViking){"Olaf", "Denmark"}, 24);
@@ -406,7 +406,7 @@ int main()
Vikings_value *v = Vikings_get_mut(&vikings, (RViking){"Einar", "Norway"});
if (v) v->second += 3; // add 3 hp points to Einar
- c_FORPAIR (vk, hp, Vikings, vikings) {
+ c_forpair (vk, hp, Vikings, vikings) {
printf("%s of %s has %d hp\n", cstr_str(&_.vk->name), cstr_str(&_.vk->country), *_.hp);
}
}
diff --git a/docs/cpque_api.md b/docs/cpque_api.md
index 48a5b29e..991623d7 100644
--- a/docs/cpque_api.md
+++ b/docs/cpque_api.md
@@ -76,19 +76,19 @@ int main()
stc64_uniform_t dist = stc64_uniform_new(0, N * 10);
// Declare heap, with defered drop()
- c_AUTO (cpque_i, heap)
+ c_auto (cpque_i, heap)
{
// Push ten million random numbers to priority queue.
- c_FORRANGE (N)
+ c_forrange (N)
cpque_i_push(&heap, stc64_uniform(&rng, &dist));
// Add some negative ones.
int nums[] = {-231, -32, -873, -4, -343};
- c_FORRANGE (i, c_ARRAYLEN(nums))
+ c_forrange (i, c_ARRAYLEN(nums))
cpque_i_push(&heap, nums[i]);
// Extract and display the fifty smallest.
- c_FORRANGE (50) {
+ c_forrange (50) {
printf("%" PRId64 " ", *cpque_i_top(&heap));
cpque_i_pop(&heap);
}
diff --git a/docs/cqueue_api.md b/docs/cqueue_api.md
index 212cdabe..9ea4b148 100644
--- a/docs/cqueue_api.md
+++ b/docs/cqueue_api.md
@@ -70,13 +70,13 @@ int main() {
cqueue_i Q = cqueue_i_init();
// push() and pop() a few.
- c_FORRANGE (i, 20)
+ c_forrange (i, 20)
cqueue_i_push(&Q, i);
- c_FORRANGE (5)
+ c_forrange (5)
cqueue_i_pop(&Q);
- c_FOREACH (i, cqueue_i, Q)
+ c_foreach (i, cqueue_i, Q)
printf(" %d", *i.ref);
cqueue_i_drop(&Q);
diff --git a/docs/crandom_api.md b/docs/crandom_api.md
index 391c485f..e69cc539 100644
--- a/docs/crandom_api.md
+++ b/docs/crandom_api.md
@@ -94,14 +94,14 @@ int main()
// Create histogram map
csmap_i mhist = csmap_i_init();
- c_FORRANGE (N) {
+ c_forrange (N) {
int index = (int) round( stc64_normalf(&rng, &dist) );
csmap_i_emplace(&mhist, index, 0).ref->second += 1;
}
// Print the gaussian bar chart
cstr bar = cstr_init();
- c_FOREACH (i, csmap_i, mhist) {
+ c_foreach (i, csmap_i, mhist) {
int n = (int)(i.ref->second * StdDev * Scale * 2.5 / N);
if (n > 0) {
cstr_resize(&bar, n, '*');
diff --git a/docs/cregex_api.md b/docs/cregex_api.md
index a115b4af..8cabb6fc 100644
--- a/docs/cregex_api.md
+++ b/docs/cregex_api.md
@@ -130,19 +130,19 @@ if (cregex_find_pattern(pattern, input, match, CREG_DEFAULT))
To compile, use: `gcc first_match.c src/cregex.c src/utf8code.c`.
In order to use a callback function in the replace call, see `examples/regex_replace.c`.
-### Iterate through regex matches, *c_FORMATCH*
+### Iterate through regex matches, *c_formatch*
To iterate multiple matches in an input string, you may use
```c
csview match[5] = {0};
while (cregex_find(&re, input, match, CREG_M_NEXT) == CREG_OK)
- c_FORRANGE (k, cregex_captures(&re))
+ c_forrange (k, cregex_captures(&re))
printf("submatch %lld: %.*s\n", k, c_SVARG(match[k]));
```
There is also a safe macro which simplifies this:
```c
-c_FORMATCH (it, &re, input)
- c_FORRANGE (k, cregex_captures(&re))
+c_formatch (it, &re, input)
+ c_forrange (k, cregex_captures(&re))
printf("submatch %lld: %.*s\n", k, c_SVARG(it.match[k]));
```
@@ -223,7 +223,7 @@ For reference, **cregex** uses the following files:
## Limitations
The main goal of **cregex** is to be small and fast with limited but useful unicode support. In order to reach these goals, **cregex** currently does not support the following features (non-exhaustive list):
-- In order to limit table sizes, most general UTF8 character classes are missing, like \p{L}, \p{S}, and all specific scripts like \p{Greek} etc. Some/all of these may be added in the future as an alternative source file with unicode tables to link with.
+- In order to limit table sizes, most general UTF8 character classes are missing, like \p{L}, \p{S}, and most specific scripts like \p{Tibetan}. Some/all of these may be added in the future as an alternative source file with unicode tables to link with. Currently, only characters from from the Basic Multilingual Plane (BMP) are supported, which contains most commonly used characters (i.e. none of the "supplementary planes").
- {n, m} syntax for repeating previous token min-max times.
- Non-capturing groups
- Lookaround and backreferences (cannot be implemented efficiently).
diff --git a/docs/cset_api.md b/docs/cset_api.md
index ef4df63b..1c38d000 100644
--- a/docs/cset_api.md
+++ b/docs/cset_api.md
@@ -86,15 +86,14 @@ cset_X_value cset_X_value_clone(cset_X_value val);
int main ()
{
- c_AUTO (cset_str, fifth)
+ c_auto (cset_str, fifth)
{
- c_AUTO (cset_str, first, second)
- c_AUTO (cset_str, third, fourth)
+ c_auto (cset_str, first, second)
+ c_auto (cset_str, third, fourth)
{
- c_FORLIST (i, const char*, {"red", "green", "blue"})
- cset_str_emplace(&second, *i.ref);
+ second = c_make(cset_str, {"red", "green", "blue"});
- c_FORLIST (i, const char*, {"orange", "pink", "yellow"})
+ c_forlist (i, const char*, {"orange", "pink", "yellow"})
cset_str_emplace(&third, *i.ref);
cset_str_emplace(&fourth, "potatoes");
@@ -102,14 +101,14 @@ int main ()
cset_str_emplace(&fourth, "flour");
fifth = cset_str_clone(second);
- c_FOREACH (i, cset_str, third)
+ c_foreach (i, cset_str, third)
cset_str_emplace(&fifth, cstr_str(i.ref));
- c_FOREACH (i, cset_str, fourth)
+ c_foreach (i, cset_str, fourth)
cset_str_emplace(&fifth, cstr_str(i.ref));
}
printf("fifth contains:\n\n");
- c_FOREACH (i, cset_str, fifth)
+ c_foreach (i, cset_str, fifth)
printf("%s\n", cstr_str(i.ref));
}
}
diff --git a/docs/csmap_api.md b/docs/csmap_api.md
index b090f737..80fa96fb 100644
--- a/docs/csmap_api.md
+++ b/docs/csmap_api.md
@@ -111,16 +111,16 @@ csmap_X_raw csmap_X_value_toraw(csmap_X_value* pval);
int main()
{
// Create a sorted map of three strings (maps to string)
- c_AUTO (csmap_str, colors) // RAII
+ c_auto (csmap_str, colors) // RAII
{
- c_FORLIST (i, csmap_str_raw, {
+ colors = c_make(csmap_str, {
{"RED", "#FF0000"},
{"GREEN", "#00FF00"},
{"BLUE", "#0000FF"}
- }) csmap_str_emplace(&colors, c_PAIR(i.ref));
+ });
// Iterate and print keys and values of sorted map
- c_FOREACH (i, csmap_str, colors) {
+ c_foreach (i, csmap_str, colors) {
printf("Key:[%s] Value:[%s]\n", cstr_str(&i.ref->first), cstr_str(&i.ref->second));
}
@@ -157,9 +157,9 @@ int main()
{
uint32_t col = 0xcc7744ff;
csmap_id idnames = csmap_id_init();
- c_DEFER (csmap_id_drop(&idnames))
+ c_defer (csmap_id_drop(&idnames))
{
- c_FORLIST (i, csmap_id_raw, { {100, "Red"}, {110, "Blue"} })
+ c_forlist (i, csmap_id_raw, { {100, "Red"}, {110, "Blue"} })
csmap_id_emplace(&idnames, c_PAIR(i.ref));
// put replaces existing mapped value:
@@ -171,7 +171,7 @@ int main()
// emplace adds only when key does not exist:
csmap_id_emplace(&idnames, 100, "Green");
- c_FOREACH (i, csmap_id, idnames)
+ c_foreach (i, csmap_id, idnames)
printf("%d: %s\n", i.ref->first, cstr_str(&i.ref->second));
}
}
@@ -204,14 +204,14 @@ static int Vec3i_cmp(const Vec3i* a, const Vec3i* b) {
int main()
{
- c_AUTO (csmap_vi, vecs)
+ c_auto (csmap_vi, vecs)
{
csmap_vi_insert(&vecs, (Vec3i){100, 0, 0}, 1);
csmap_vi_insert(&vecs, (Vec3i){0, 100, 0}, 2);
csmap_vi_insert(&vecs, (Vec3i){0, 0, 100}, 3);
csmap_vi_insert(&vecs, (Vec3i){100, 100, 100}, 4);
- c_FOREACH (i, csmap_vi, vecs)
+ c_foreach (i, csmap_vi, vecs)
printf("{ %3d, %3d, %3d }: %d\n", i.ref->first.x, i.ref->first.y, i.ref->first.z, i.ref->second);
}
}
@@ -237,15 +237,15 @@ typedef struct { int x, y, z; } Vec3i;
int main()
{
- // equivalent to: c_AUTO (csmap_iv, vecs)
- c_WITH (csmap_iv vecs = csmap_iv_init(), csmap_iv_drop(&vecs))
+ // equivalent to: c_auto (csmap_iv, vecs)
+ c_with (csmap_iv vecs = csmap_iv_init(), csmap_iv_drop(&vecs))
{
csmap_iv_insert(&vecs, 1, (Vec3i){100, 0, 0});
csmap_iv_insert(&vecs, 2, (Vec3i){0, 100, 0});
csmap_iv_insert(&vecs, 3, (Vec3i){0, 0, 100});
csmap_iv_insert(&vecs, 4, (Vec3i){100, 100, 100});
- c_FOREACH (i, csmap_iv, vecs)
+ c_foreach (i, csmap_iv, vecs)
printf("%d: { %3d, %3d, %3d }\n", i.ref->first, i.ref->second.x, i.ref->second.y, i.ref->second.z);
}
}
diff --git a/docs/cspan_api.md b/docs/cspan_api.md
index d0463b0a..2bd93a2b 100644
--- a/docs/cspan_api.md
+++ b/docs/cspan_api.md
@@ -84,7 +84,7 @@ if __name__ == '__main__':
# 19 20 23 24
# 19 20 23 24
```
-... can be done in C with cspan:
+... can be written in C using cspan:
```c
#include <c11/fmt.h>
#include <stc/cspan.h>
@@ -97,12 +97,12 @@ int main() {
myspan3 ss3 = cspan_slice(myspan3, &ms3, {c_ALL}, {1,3}, {2,c_END});
myspan2 ss2 = cspan_submd3(&ss3, 1);
- c_FORRANGE (i, ss2.shape[0])
- c_FORRANGE (j, ss2.shape[1])
+ c_forrange (i, ss2.shape[0])
+ c_forrange (j, ss2.shape[1])
fmt_print(" {}", *cspan_at(&ss2, i, j));
puts("");
- c_FOREACH (i, myspan2, ss2)
+ c_foreach (i, myspan2, ss2)
fmt_print(" {}", *i.ref);
}
```
@@ -147,7 +147,7 @@ int main()
Span2 span2 = cspan_submd3(&span3, 1);
puts("\niterate span2 flat:");
- c_FOREACH (i, Span2, span2)
+ c_foreach (i, Span2, span2)
fmt_print(" {}", *i.ref);
puts("");
@@ -155,9 +155,9 @@ int main()
Span3 ss3 = cspan_slice(Span3, &span3, {c_ALL}, {3,4}, {c_ALL});
puts("\niterate ss3 by dimensions:");
- c_FORRANGE (i, ss3.shape[0]) {
- c_FORRANGE (j, ss3.shape[1]) {
- c_FORRANGE (k, ss3.shape[2])
+ c_forrange (i, ss3.shape[0]) {
+ c_forrange (j, ss3.shape[1]) {
+ c_forrange (k, ss3.shape[2])
fmt_print(" {:2}", *cspan_at(&ss3, i, j, k));
fmt_print(" |");
}
@@ -167,8 +167,8 @@ int main()
Span2 ss2 = cspan_slice(Span2, &span3, {c_ALL}, {3}, {c_ALL});
puts("\niterate ss2 by dimensions:");
- c_FORRANGE (i, ss2.shape[0]) {
- c_FORRANGE (j, ss2.shape[1]) {
+ c_forrange (i, ss2.shape[0]) {
+ c_forrange (j, ss2.shape[1]) {
fmt_print(" {:2}", *cspan_at(&ss2, i, j));
fmt_print(" |");
}
@@ -176,7 +176,7 @@ int main()
}
puts("\niterate ss2 flat:");
- c_FOREACH (i, Span2, ss2)
+ c_foreach (i, Span2, ss2)
fmt_print(" {:2}", *i.ref);
puts("");
}
diff --git a/docs/csset_api.md b/docs/csset_api.md
index 7e068909..3d7698ed 100644
--- a/docs/csset_api.md
+++ b/docs/csset_api.md
@@ -83,13 +83,12 @@ csset_X_value csset_X_value_clone(csset_X_value val);
int main ()
{
- c_AUTO (csset_str, first, second, third)
- c_AUTO (csset_str, fourth, fifth)
+ c_auto (csset_str, first, second, third)
+ c_auto (csset_str, fourth, fifth)
{
- c_FORLIST (i, const char*, {"red", "green", "blue"})
- csset_str_emplace(&second, *i.ref);
+ second = c_make(csset_str, {"red", "green", "blue"});
- c_FORLIST (i, const char*, {"orange", "pink", "yellow"})
+ c_forlist (i, const char*, {"orange", "pink", "yellow"})
csset_str_emplace(&third, *i.ref);
csset_str_emplace(&fourth, "potatoes");
@@ -97,13 +96,13 @@ int main ()
csset_str_emplace(&fourth, "flour");
fifth = csset_str_clone(second);
- c_FOREACH (i, csset_str, third)
+ c_foreach (i, csset_str, third)
csset_str_emplace(&fifth, cstr_str(i.ref));
- c_FOREACH (i, csset_str, fourth)
+ c_foreach (i, csset_str, fourth)
csset_str_emplace(&fifth, cstr_str(i.ref));
printf("fifth contains:\n\n");
- c_FOREACH (i, csset_str, fifth)
+ c_foreach (i, csset_str, fifth)
printf("%s\n", cstr_str(i.ref));
}
}
diff --git a/docs/cstr_api.md b/docs/cstr_api.md
index 37316d4d..64099675 100644
--- a/docs/cstr_api.md
+++ b/docs/cstr_api.md
@@ -160,7 +160,7 @@ char* cstrnstrn(const char* str, const char* search, intptr_t slen, intpt
#include <stc/cstr.h>
int main() {
- c_AUTO (cstr, s0, s1, full_path) {
+ c_auto (cstr, s0, s1, full_path) {
s0 = cstr_lit("Initialization without using strlen().");
printf("%s\nLength: %" c_ZI "\n\n", cstr_str(&s0), cstr_size(&s0));
diff --git a/docs/csview_api.md b/docs/csview_api.md
index e3c65766..29c59d9c 100644
--- a/docs/csview_api.md
+++ b/docs/csview_api.md
@@ -83,11 +83,11 @@ csview cstr_u8_substr(const cstr* self, intptr_t bytepos, intptr_t u8le
csview cstr_slice(const cstr* self, intptr_t p1, intptr_t p2);
csview cstr_slice_ex(const cstr* s, intptr_t p, intptr_t q); // negative p or q count from end
```
-#### Iterate tokens with *c_FORTOKEN*, *c_FORTOKEN_SV*
+#### Iterate tokens with *c_fortoken*, *c_fortoken_sv*
To iterate tokens in an input string separated by a string:
```c
-c_FORTOKEN (i, "hello, one, two, three", ", ")
+c_fortoken (i, "hello, one, two, three", ", ")
printf("token: %.*s\n", c_SVARG(i.token));
```
@@ -151,12 +151,12 @@ red Apples
int main()
{
- c_AUTO (cstr, s1) {
+ c_auto (cstr, s1) {
s1 = cstr_lit("hell😀 w😀rld");
cstr_u8_replace_at(&s1, cstr_find(&s1, "😀rld"), 1, c_SV("ø"));
printf("%s\n", cstr_str(&s1));
- c_FOREACH (i, cstr, s1)
+ c_foreach (i, cstr, s1)
printf("%.*s,", c_SVARG(i.u8.chr));
}
}
@@ -176,7 +176,7 @@ and does not depend on null-terminated strings. *string_split()* function return
void print_split(csview input, const char* sep)
{
- c_FORTOKEN_SV (i, input, sep)
+ c_fortoken_sv (i, input, sep)
printf("[%.*s]\n", c_SVARG(i.token));
}
@@ -188,7 +188,7 @@ cstack_str string_split(csview input, const char* sep)
{
cstack_str out = cstack_str_init();
- c_FORTOKEN_SV (i, input, sep)
+ c_fortoken_sv (i, input, sep)
cstack_str_push(&out, cstr_from_sv(i.token));
return out;
@@ -201,8 +201,8 @@ int main()
print_split(c_SV("This has no matching separator"), "xx");
puts("");
- c_WITH (cstack_str s = string_split(c_SV("Split,this,,string,now,"), ","), cstack_str_drop(&s))
- c_FOREACH (i, cstack_str, s)
+ c_with (cstack_str s = string_split(c_SV("Split,this,,string,now,"), ","), cstack_str_drop(&s))
+ c_foreach (i, cstack_str, s)
printf("[%s]\n", cstr_str(i.ref));
}
```
diff --git a/docs/cvec_api.md b/docs/cvec_api.md
index 057caa7c..68e08cb2 100644
--- a/docs/cvec_api.md
+++ b/docs/cvec_api.md
@@ -119,18 +119,18 @@ cvec_X_value cvec_X_value_clone(cvec_X_value val);
int main()
{
// Create a vector containing integers
- c_AUTO (cvec_int, vec)
+ c_auto (cvec_int, vec)
{
// Add two integers to vector
cvec_int_push(&vec, 25);
cvec_int_push(&vec, 13);
// Append a set of numbers
- c_FORLIST (i, int, {7, 5, 16, 8})
+ c_forlist (i, int, {7, 5, 16, 8})
cvec_int_push(&vec, *i.ref);
printf("initial:");
- c_FOREACH (k, cvec_int, vec) {
+ c_foreach (k, cvec_int, vec) {
printf(" %d", *k.ref);
}
@@ -138,7 +138,7 @@ int main()
cvec_int_sort(&vec);
printf("\nsorted:");
- c_FOREACH (k, cvec_int, vec) {
+ c_foreach (k, cvec_int, vec) {
printf(" %d", *k.ref);
}
}
@@ -170,7 +170,7 @@ int main() {
printf("%s\n", cstr_str(&names.data[1])); // Access second element
- c_FOREACH (i, cvec_str, names)
+ c_foreach (i, cvec_str, names)
printf("item: %s\n", cstr_str(i.ref));
cvec_str_drop(&names);
@@ -219,7 +219,7 @@ int main(void) {
UVec vec2 = UVec_clone(vec);
- c_FOREACH (i, UVec, vec2)
+ c_foreach (i, UVec, vec2)
printf("%s: %d\n", cstr_str(&i.ref->name), i.ref->id);
c_drop(UVec, &vec, &vec2); // cleanup
diff --git a/include/stc/algo/crange.h b/include/stc/algo/crange.h
index 3993e615..1b840516 100644
--- a/include/stc/algo/crange.h
+++ b/include/stc/algo/crange.h
@@ -28,13 +28,13 @@
int main()
{
crange r1 = crange_make(80, 90);
- c_FOREACH (i, crange, r1)
+ c_foreach (i, crange, r1)
printf(" %lld", *i.ref);
puts("");
// use a temporary crange object.
int a = 100, b = INT32_MAX;
- c_FORFILTER (i, crange, crange_obj(a, b, 8)
+ c_forfilter (i, crange, crange_obj(a, b, 8)
, i.index > 10
, c_flt_take(i, 3))
printf(" %lld", *i.ref);
diff --git a/include/stc/algo/filter.h b/include/stc/algo/filter.h
index 9037c984..b2b59fa6 100644
--- a/include/stc/algo/filter.h
+++ b/include/stc/algo/filter.h
@@ -28,15 +28,14 @@
int main()
{
- c_WITH (cstack_int stk = {0}, cstack_int_drop(&stk)) {
- c_FORLIST (i, int, {1, 2, 3, 4, 5, 6, 7, 8, 9})
- cstack_int_push(&stk, i);
-
- c_FOREACH (i, cstack_int, stk)
+ c_with (cstack_int stk = c_make(cstack_int, {1, 2, 3, 4, 5, 6, 7, 8, 9}),
+ cstack_int_drop(&stk))
+ {
+ c_foreach (i, cstack_int, stk)
printf(" %d", *i.ref);
puts("");
- c_FORFILTER (i, cstack_int, stk
+ c_forfilter (i, cstack_int, stk
, c_flt_skipwhile(i, *i.ref < 3)
&& (*i.ref & 1) == 0 // even only
, c_flt_take(i, 2)) // break after 2
@@ -59,15 +58,15 @@ int main()
#define c_flt_skipwhile(i, pred) ((i).s2[(i).s2top++] |= !(pred))
#define c_flt_takewhile(i, pred) !c_flt_skipwhile(i, pred)
-#define c_FORFILTER(...) c_MACRO_OVERLOAD(c_FORFILTER, __VA_ARGS__)
+#define c_forfilter(...) c_MACRO_OVERLOAD(c_forfilter, __VA_ARGS__)
-#define c_FORFILTER_4(i, C, cnt, filter) \
- c_FORFILTER_B(i, C, C##_begin(&cnt), filter)
+#define c_forfilter_4(i, C, cnt, filter) \
+ c_forfilter_B(i, C, C##_begin(&cnt), filter)
-#define c_FORFILTER_5(i, C, cnt, filter, cond) \
- c_FORFILTER_B(i, C, C##_begin(&cnt), filter) if (!(cond)) break; else
+#define c_forfilter_5(i, C, cnt, filter, cond) \
+ c_forfilter_B(i, C, C##_begin(&cnt), filter) if (!(cond)) break; else
-#define c_FORFILTER_B(i, C, start, filter) \
+#define c_forfilter_B(i, C, start, filter) \
for (struct {C##_iter it; C##_value *ref; \
uint32_t s1[c_NFILTERS], index, count; \
bool s2[c_NFILTERS]; uint8_t s1top, s2top;} \
diff --git a/include/stc/cbits.h b/include/stc/cbits.h
index d72be230..0c169b88 100644
--- a/include/stc/cbits.h
+++ b/include/stc/cbits.h
@@ -27,13 +27,13 @@ Similar to boost::dynamic_bitset / std::bitset
#include "cbits.h"
int main() {
- c_WITH (cbits bset = cbits_with_size(23, true), cbits_drop(&bset))
+ c_with (cbits bset = cbits_with_size(23, true), cbits_drop(&bset))
{
cbits_reset(&bset, 9);
cbits_resize(&bset, 43, false);
printf("%4zu: ", cbits_size(&bset));
- c_FORRANGE (i, cbits_size(&bset))
+ c_forrange (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_forrange (i, cbits_size(&bset))
printf("%d", cbits_at(&bset, i));
puts("");
}
diff --git a/include/stc/cbox.h b/include/stc/cbox.h
index c914152c..08449031 100644
--- a/include/stc/cbox.h
+++ b/include/stc/cbox.h
@@ -45,7 +45,7 @@ void Person_drop(Person* p) {
#include <stc/cbox.h>
int main() {
- c_AUTO (PBox, p, q)
+ c_auto (PBox, p, q)
{
p = PBox_from(Person_from("John Smiths", "[email protected]"));
q = PBox_clone(p);
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index d7d2d804..0b3083ef 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -173,65 +173,65 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle,
/* Control block macros */
-#define c_FOREACH(...) c_MACRO_OVERLOAD(c_FOREACH, __VA_ARGS__)
-#define c_FOREACH_3(it, C, cnt) \
+#define c_foreach(...) c_MACRO_OVERLOAD(c_foreach, __VA_ARGS__)
+#define c_foreach_3(it, C, cnt) \
for (C##_iter it = C##_begin(&cnt); it.ref; C##_next(&it))
-#define c_FOREACH_4(it, C, start, finish) \
+#define c_foreach_4(it, C, start, finish) \
for (C##_iter it = start, *_endref = (C##_iter*)(finish).ref \
; it.ref != (C##_value*)_endref; C##_next(&it))
-#define c_FORWHILE(i, C, start, cond) \
+#define c_forwhile(i, C, start, cond) \
for (struct {C##_iter it; C##_value *ref; intptr_t index;} \
i = {.it=start, .ref=i.it.ref}; i.it.ref && (cond) \
; C##_next(&i.it), i.ref = i.it.ref, ++i.index)
-#define c_FORPAIR(key, val, C, cnt) /* structured binding */ \
+#define c_forpair(key, val, C, cnt) /* structured binding */ \
for (struct {C##_iter it; const C##_key* key; C##_mapped* val;} _ = {.it=C##_begin(&cnt)} \
; _.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) \
+#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 (long long i=start, _end=(long long)(stop); i < _end; ++i)
-#define c_FORRANGE_4(i, start, stop, step) \
+#define c_forrange_4(i, start, stop, step) \
for (long long i=start, _inc=step, _end=(long long)(stop) - (_inc > 0) \
; (_inc > 0) ^ (i > _end); i += _inc)
#ifndef __cplusplus
- #define c_FORLIST(it, T, ...) \
+ #define c_forlist(it, T, ...) \
for (struct {T* data; T* ref; int size, index;} \
it = {.data=(T[])__VA_ARGS__, .ref=it.data, .size=(int)(sizeof((T[])__VA_ARGS__)/sizeof(T))} \
; it.index < it.size; ++it.ref, ++it.index)
#else
#include <initializer_list>
- #define c_FORLIST(it, T, ...) \
+ #define c_forlist(it, T, ...) \
for (struct {std::initializer_list<T> _il; std::initializer_list<T>::iterator data, ref; size_t size, index;} \
it = {._il=__VA_ARGS__, .data=it._il.begin(), .ref=it.data, .size=it._il.size()} \
; it.index < it.size; ++it.ref, ++it.index)
#endif
-#define c_WITH(...) c_MACRO_OVERLOAD(c_WITH, __VA_ARGS__)
-#define c_WITH_2(declvar, drop) for (declvar, **_c_i = NULL; !_c_i; ++_c_i, drop)
-#define c_WITH_3(declvar, pred, drop) for (declvar, **_c_i = NULL; !_c_i && (pred); ++_c_i, drop)
-#define c_SCOPE(init, drop) for (int _c_i = (init, 1); _c_i; --_c_i, drop)
-#define c_DEFER(...) for (int _c_i = 1; _c_i; --_c_i, __VA_ARGS__)
+#define c_with(...) c_MACRO_OVERLOAD(c_with, __VA_ARGS__)
+#define c_with_2(declvar, drop) for (declvar, **_c_i = NULL; !_c_i; ++_c_i, drop)
+#define c_with_3(declvar, pred, drop) for (declvar, **_c_i = NULL; !_c_i && (pred); ++_c_i, drop)
+#define c_scope(init, drop) for (int _c_i = (init, 1); _c_i; --_c_i, drop)
+#define c_defer(...) for (int _c_i = 1; _c_i; --_c_i, __VA_ARGS__)
-#define c_AUTO(...) c_MACRO_OVERLOAD(c_AUTO, __VA_ARGS__)
-#define c_AUTO_2(C, a) \
- c_WITH_2(C a = C##_init(), C##_drop(&a))
-#define c_AUTO_3(C, a, b) \
- c_WITH_2(c_EXPAND(C a = C##_init(), b = C##_init()), \
+#define c_auto(...) c_MACRO_OVERLOAD(c_auto, __VA_ARGS__)
+#define c_auto_2(C, a) \
+ c_with_2(C a = C##_init(), C##_drop(&a))
+#define c_auto_3(C, a, b) \
+ c_with_2(c_EXPAND(C a = C##_init(), b = C##_init()), \
(C##_drop(&b), C##_drop(&a)))
-#define c_AUTO_4(C, a, b, c) \
- c_WITH_2(c_EXPAND(C a = C##_init(), b = C##_init(), c = C##_init()), \
+#define c_auto_4(C, a, b, c) \
+ c_with_2(c_EXPAND(C a = C##_init(), b = C##_init(), c = C##_init()), \
(C##_drop(&c), C##_drop(&b), C##_drop(&a)))
-#define c_AUTO_5(C, a, b, c, d) \
- c_WITH_2(c_EXPAND(C a = C##_init(), b = C##_init(), c = C##_init(), d = C##_init()), \
+#define c_auto_5(C, a, b, c, d) \
+ c_with_2(c_EXPAND(C a = C##_init(), b = C##_init(), c = C##_init(), d = C##_init()), \
(C##_drop(&d), C##_drop(&c), C##_drop(&b), C##_drop(&a)))
/* Generic functions */
-#define c_drop(C, ...) do { c_FORLIST (_i, C*, {__VA_ARGS__}) C##_drop(*_i.ref); } while(0)
+#define c_drop(C, ...) do { c_forlist (_i, C*, {__VA_ARGS__}) C##_drop(*_i.ref); } while(0)
#define c_find_if(...) c_MACRO_OVERLOAD(c_find_if, __VA_ARGS__)
#define c_find_if_4(it, C, cnt, pred) do { \
intptr_t index = 0; \
diff --git a/include/stc/clist.h b/include/stc/clist.h
index de874927..f257bc19 100644
--- a/include/stc/clist.h
+++ b/include/stc/clist.h
@@ -34,19 +34,19 @@
int main()
{
- c_AUTO (clist_ix, list)
+ c_auto (clist_ix, list)
{
int n;
for (int i = 0; i < 1000000; ++i) // one million
clist_ix_push_back(&list, crandom() >> 32);
n = 0;
- c_FOREACH (i, clist_ix, list)
+ c_foreach (i, clist_ix, list)
if (++n % 10000 == 0) printf("%8d: %10zu\n", n, *i.ref);
// Sort them...
clist_ix_sort(&list); // mergesort O(n*log n)
n = 0;
puts("sorted");
- c_FOREACH (i, clist_ix, list)
+ c_foreach (i, clist_ix, list)
if (++n % 10000 == 0) printf("%8d: %10zu\n", n, *i.ref);
}
}
@@ -273,7 +273,7 @@ _clist_mergesort(clist_VOID_node *list, int (*cmp)(const clist_VOID_node*, const
STC_DEF _cx_self
_cx_memb(_clone)(_cx_self cx) {
_cx_self out = _cx_memb(_init)();
- c_FOREACH (it, _cx_self, cx)
+ c_foreach (it, _cx_self, cx)
_cx_memb(_push_back)(&out, i_keyclone((*it.ref)));
return out;
}
@@ -406,7 +406,7 @@ _cx_memb(_split_off)(_cx_self* self, _cx_iter it1, _cx_iter it2) {
STC_DEF _cx_iter
_cx_memb(_find_in)(_cx_iter it1, _cx_iter it2, _cx_raw val) {
- c_FOREACH (it, _cx_self, it1, it2) {
+ c_foreach (it, _cx_self, it1, it2) {
_cx_raw r = i_keyto(it.ref);
if (i_eq((&r), (&val)))
return it;
diff --git a/include/stc/cmap.h b/include/stc/cmap.h
index f3c82469..0553823b 100644
--- a/include/stc/cmap.h
+++ b/include/stc/cmap.h
@@ -31,7 +31,7 @@
#include <stc/cmap.h>
int main(void) {
- c_WITH (cmap_ichar m = cmap_ichar_init(), cmap_ichar_drop(&m))
+ c_with (cmap_ichar m = cmap_ichar_init(), cmap_ichar_drop(&m))
{
cmap_ichar_emplace(&m, 5, 'a');
cmap_ichar_emplace(&m, 8, 'b');
@@ -42,7 +42,7 @@ int main(void) {
cmap_ichar_emplace_or_assign(&m, 5, 'd'); // update
cmap_ichar_erase(&m, 8);
- c_FOREACH (i, cmap_ichar, m)
+ c_foreach (i, cmap_ichar, m)
printf("map %d: %c\n", i.ref->first, i.ref->second);
}
}
diff --git a/include/stc/cqueue.h b/include/stc/cqueue.h
index 1f90e00e..67909f8e 100644
--- a/include/stc/cqueue.h
+++ b/include/stc/cqueue.h
@@ -33,7 +33,7 @@ int main() {
stc64_t rng = stc64_new(1234);
stc64_uniform_t dist = stc64_uniform_new(0, n);
- c_AUTO (cqueue_int, Q)
+ c_auto (cqueue_int, Q)
{
// Push ten million random numbers onto the queue.
for (int i=0; i<n; ++i)
diff --git a/include/stc/cregex.h b/include/stc/cregex.h
index fa136f16..a48b4c49 100644
--- a/include/stc/cregex.h
+++ b/include/stc/cregex.h
@@ -80,7 +80,7 @@ typedef struct {
csview match[CREG_MAX_CAPTURES];
} cregex_iter;
-#define c_FORMATCH(it, Re, Input) \
+#define c_formatch(it, Re, Input) \
for (cregex_iter it = {Re, Input}; \
cregex_find_4(it.re, it.input, it.match, CREG_M_NEXT) == CREG_OK; )
diff --git a/include/stc/cset.h b/include/stc/cset.h
index c7ade49a..58cbeb3e 100644
--- a/include/stc/cset.h
+++ b/include/stc/cset.h
@@ -33,7 +33,7 @@ int main(void) {
cset_sx_insert(&s, 5);
cset_sx_insert(&s, 8);
- c_FOREACH (i, cset_sx, s)
+ c_foreach (i, cset_sx, s)
printf("set %d\n", *i.ref);
cset_sx_drop(&s);
}
diff --git a/include/stc/csmap.h b/include/stc/csmap.h
index 6a1899b9..6a359fbb 100644
--- a/include/stc/csmap.h
+++ b/include/stc/csmap.h
@@ -32,7 +32,7 @@
#include <stc/csmap.h>
int main(void) {
- c_WITH (csmap_sx m = csmap_sx_init(), csmap_sx_drop(&m))
+ c_with (csmap_sx m = csmap_sx_init(), csmap_sx_drop(&m))
{
csmap_sx_emplace(&m, "Testing one", 1.234);
csmap_sx_emplace(&m, "Testing two", 12.34);
@@ -43,7 +43,7 @@ int main(void) {
csmap_sx_emplace_or_assign(&m, "Testing three", 1000.0); // update
csmap_sx_erase(&m, "Testing two");
- c_FOREACH (i, csmap_sx, m)
+ c_foreach (i, csmap_sx, m)
printf("map %s: %g\n", cstr_str(&i.ref->first), i.ref->second);
}
}
diff --git a/include/stc/cspan.h b/include/stc/cspan.h
index 62de174a..bbaaf6c0 100644
--- a/include/stc/cspan.h
+++ b/include/stc/cspan.h
@@ -43,11 +43,11 @@ int demo2() {
int array[] = {10, 20, 30, 23, 22, 21};
Intspan span = cspan_from_array(array);
- c_FOREACH (i, Intspan, span)
+ c_foreach (i, Intspan, span)
printf(" %d", *i.ref);
puts("");
- c_FORFILTER (i, Intspan, span,
+ c_forfilter (i, Intspan, span,
, c_flt_skipwhile(i, *i.ref < 25)
&& (*i.ref & 1) == 0 // even only
, c_flt_take(i, 2)) // break after 2
diff --git a/include/stc/csset.h b/include/stc/csset.h
index 392d258c..c14d2a6a 100644
--- a/include/stc/csset.h
+++ b/include/stc/csset.h
@@ -36,7 +36,7 @@ int main(void) {
csset_i_insert(&s, 3);
csset_i_insert(&s, 5);
- c_FOREACH (k, csset_i, s)
+ c_foreach (k, csset_i, s)
printf("set %d\n", *k.ref);
csset_i_drop(&s);
}
diff --git a/include/stc/csview.h b/include/stc/csview.h
index a30672cd..748f7d30 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -115,13 +115,13 @@ STC_API csview csview_substr_ex(csview sv, intptr_t pos, intptr_t n);
STC_API csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2);
STC_API csview csview_token(csview sv, const char* sep, intptr_t* start);
-#define c_FORTOKEN_SV(it, inputsv, sep) \
+#define c_fortoken_sv(it, inputsv, sep) \
for (struct { csview _inp, token, *ref; const char *_sep; intptr_t pos; } \
it = {._inp=inputsv, .token=it._inp, .ref=&it.token, ._sep=sep} \
; it.pos <= it._inp.size && (it.token = csview_token(it._inp, it._sep, &it.pos)).str ; )
-#define c_FORTOKEN(it, input, sep) \
- c_FORTOKEN_SV(it, csview_from(input), sep)
+#define c_fortoken(it, input, sep) \
+ c_fortoken_sv(it, csview_from(input), sep)
/* csview interaction with cstr: */
#ifdef CSTR_H_INCLUDED
diff --git a/include/stc/priv/altnames.h b/include/stc/priv/altnames.h
index 0b01d251..bfda05ca 100644
--- a/include/stc/priv/altnames.h
+++ b/include/stc/priv/altnames.h
@@ -20,20 +20,20 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#define c_forlist c_FORLIST
-#define c_forrange c_FORRANGE
-#define c_foreach c_FOREACH
-#define c_forwhile c_FORWHILE
-#define c_forpair c_FORPAIR
-#define c_forfilter c_FORFILTER
-#define c_formatch c_FORMATCH
-#define c_fortoken c_FORTOKEN
-#define c_fortoken_sv c_FORTOKEN_SV
-#define c_auto c_AUTO
-#define c_with c_WITH
-#define c_scope c_SCOPE
-#define c_defer c_DEFER
-#define c_sv c_SV
-#define c_ARGSV c_SVARG
+#define c_FORLIST c_forlist
+#define c_FORRANGE c_forrange
+#define c_FOREACH c_foreach
+#define c_FORWHILE c_forwhile
+#define c_FORPAIR c_forpair
+#define c_FORFILTER c_forfilter
+#define c_FORMATCH c_formatch
+#define c_FORTOKEN c_fortoken
+#define c_FORTOKEN_SV c_fortoken_sv
+#define c_AUTO c_auto
+#define c_WITH c_with
+#define c_SCOPE c_scope
+#define c_DEFER c_defer
#define c_NEW c_new
#define c_ARRAYLEN c_arraylen
+#define c_ARGSV c_SVARG
+#define c_sv c_SV
diff --git a/misc/benchmarks/misc/cbits_benchmark.cpp b/misc/benchmarks/misc/cbits_benchmark.cpp
index 114ab963..dd709db1 100644
--- a/misc/benchmarks/misc/cbits_benchmark.cpp
+++ b/misc/benchmarks/misc/cbits_benchmark.cpp
@@ -42,7 +42,7 @@ int main(int argc, char **argv)
csrandom(seed);
current_time = get_time_in_ms();
- c_FORRANGE (40 * N)
+ c_forrange (40 * N)
{
uint64_t r = crandom();
bools[r & (N-1)] = r & 1<<29;
@@ -51,7 +51,7 @@ int main(int argc, char **argv)
difference1 = get_time_in_ms() - current_time;
current_time = get_time_in_ms();
- c_FORRANGE (100) c_FORRANGE (num, N)
+ c_forrange (100) c_forrange (num, N)
{
total += bools[num];
}
@@ -70,7 +70,7 @@ int main(int argc, char **argv)
current_time = get_time_in_ms();
bitset<N> bits;
- c_FORRANGE (40 * N)
+ c_forrange (40 * N)
{
uint64_t r = crandom();
bits[r & (N-1)] = r & 1<<29;
@@ -79,7 +79,7 @@ int main(int argc, char **argv)
difference1 = get_time_in_ms() - current_time;
current_time = get_time_in_ms();
- c_FORRANGE (100) c_FORRANGE (num, N)
+ c_forrange (100) c_forrange (num, N)
{
total += bits[num];
}
@@ -96,7 +96,7 @@ int main(int argc, char **argv)
current_time = get_time_in_ms();
cbits bits2 = cbits_with_size(N, false);
- c_FORRANGE (40 * N)
+ c_forrange (40 * N)
{
uint64_t r = crandom();
cbits_set_value(&bits2, r & (N-1), r & 1<<29);
@@ -105,7 +105,7 @@ int main(int argc, char **argv)
difference1 = get_time_in_ms() - current_time;
current_time = get_time_in_ms();
- c_FORRANGE (100) c_FORRANGE (num, N)
+ c_forrange (100) c_forrange (num, N)
{
total += cbits_at(&bits2, num);
}
diff --git a/misc/benchmarks/misc/rust_cmap.c b/misc/benchmarks/misc/rust_cmap.c
index 18635c35..83b7dd19 100644
--- a/misc/benchmarks/misc/rust_cmap.c
+++ b/misc/benchmarks/misc/rust_cmap.c
@@ -24,7 +24,7 @@ uint64_t romu_trio(uint64_t s[3]) {
int main()
{
- c_AUTO (cmap_u64, m) {
+ c_auto (cmap_u64, m) {
const size_t n = 50000000,
mask = (1 << 25) - 1,
ms = CLOCKS_PER_SEC/1000;
@@ -33,7 +33,7 @@ int main()
uint64_t rng[3] = {1872361123, 123879177, 87739234}, sum;
clock_t now = clock();
- c_FORRANGE (n) {
+ c_forrange (n) {
uint64_t key = romu_trio(rng) & mask;
cmap_u64_insert(&m, key, 0).ref->second += 1;
}
@@ -41,17 +41,17 @@ int main()
now = clock();
sum = 0;
- c_FORRANGE (key, mask + 1) { sum += cmap_u64_contains(&m, key); }
+ c_forrange (key, mask + 1) { sum += cmap_u64_contains(&m, key); }
printf("lookup : %" c_ZU "ms \tsum : %" c_ZU "\n", (clock() - now)/ms, sum);
now = clock();
sum = 0;
- c_FOREACH (i, cmap_u64, m) { sum += i.ref->second; }
+ c_foreach (i, cmap_u64, m) { sum += i.ref->second; }
printf("iterate : %" c_ZU "ms \tsum : %" c_ZU "\n", (clock() - now)/ms, sum);
uint64_t rng2[3] = {1872361123, 123879177, 87739234};
now = clock();
- c_FORRANGE (n) {
+ c_forrange (n) {
uint64_t key = romu_trio(rng2) & mask;
cmap_u64_erase(&m, key);
}
diff --git a/misc/benchmarks/misc/string_bench_STC.cpp b/misc/benchmarks/misc/string_bench_STC.cpp
index e252b449..ae8e4c38 100644
--- a/misc/benchmarks/misc/string_bench_STC.cpp
+++ b/misc/benchmarks/misc/string_bench_STC.cpp
@@ -37,8 +37,8 @@
cvec_str read_file(const char* name)
{
cvec_str data = cvec_str_init();
- c_AUTO (cstr, line)
- c_WITH (FILE* f = fopen(name, "r"), fclose(f))
+ c_auto (cstr, line)
+ c_with (FILE* f = fopen(name, "r"), fclose(f))
while (cstr_getline(&line, f))
cvec_str_emplace_back(&data, cstr_str(&line));
return data;
@@ -98,7 +98,7 @@ void initShortStringVec(cvec_str* vs, cvec_sv* vsv)
cvec_str_emplace_back(vs, "David");
*/
size_t num = 0;
- c_FOREACH (i, cvec_str, *vs)
+ c_foreach (i, cvec_str, *vs)
{
cvec_sv_push_back(vsv, cstr_sv(i.ref));
num += cstr_size(i.ref);
@@ -113,7 +113,7 @@ void initLongStringVec(cvec_str* vs, cvec_sv* vsv)
cvec_sv_clear(vsv);
*vs = read_file("names.txt");
- c_FOREACH (i, cvec_str, *vs) {
+ c_foreach (i, cvec_str, *vs) {
cstr_append_s(i.ref, *i.ref);
cstr_append_s(i.ref, *i.ref);
cstr_append_s(i.ref, *i.ref);
@@ -144,7 +144,7 @@ void initLongStringVec(cvec_str* vs, cvec_sv* vsv)
cvec_str_emplace_back(vs, "David David David David David David");
*/
size_t num = 0;
- c_FOREACH (i, cvec_str, *vs)
+ c_foreach (i, cvec_str, *vs)
{
cvec_sv_push_back(vsv, cstr_sv(i.ref));
num += cstr_size(i.ref);
@@ -162,7 +162,7 @@ void initMaps(const cvec_str* vs, csmap_str* mapTrans, csmap_ssv* mapSview,
cmap_ssv_clear(unordmapSview);
size_t n = 0;
- c_FOREACH (i, cvec_str, *vs)
+ c_foreach (i, cvec_str, *vs)
{
csmap_str_insert(mapTrans, cstr_clone(*i.ref), n);
csmap_ssv_insert(mapSview, cstr_clone(*i.ref), n);
@@ -185,12 +185,12 @@ const size_t MAX_LOOP = 2000;
int main()
{
- c_AUTO (cvec_str, vec_string)
- c_AUTO (cvec_sv, vec_stringview)
- c_AUTO (csmap_str, mapTrans)
- c_AUTO (csmap_ssv, mapSview)
- c_AUTO (cmap_str, unordmapTrans)
- c_AUTO (cmap_ssv, unordmapSview)
+ c_auto (cvec_str, vec_string)
+ c_auto (cvec_sv, vec_stringview)
+ c_auto (csmap_str, mapTrans)
+ c_auto (csmap_ssv, mapSview)
+ c_auto (cmap_str, unordmapTrans)
+ c_auto (cmap_ssv, unordmapSview)
{
std::cout << "Short String Benchmark" << std::endl;
std::cout << "======================" << std::endl;
@@ -243,7 +243,7 @@ void benchmark(
stopwatch.start("Trans Map with char*");
for (size_t i = 0; i < MAX_LOOP; ++i)
{
- c_FOREACH (j, cvec_str, *vec_string)
+ c_foreach (j, cvec_str, *vec_string)
{
const csmap_str_value* v = csmap_str_get(mapTrans, cstr_str(j.ref));
if (v)
@@ -257,7 +257,7 @@ void benchmark(
stopwatch.start("Trans Map with string_view");
for (size_t i = 0; i < MAX_LOOP; ++i)
{
- c_FOREACH (j, cvec_sv, *vec_stringview)
+ c_foreach (j, cvec_sv, *vec_stringview)
{
const csmap_ssv_value* v = csmap_ssv_get(mapSview, *j.ref);
if (v)
@@ -271,7 +271,7 @@ void benchmark(
stopwatch.start("Trans Unord Map with char*");
for (size_t i = 0; i < MAX_LOOP; ++i)
{
- c_FOREACH (j, cvec_str, *vec_string)
+ c_foreach (j, cvec_str, *vec_string)
{
const cmap_str_value* v = cmap_str_get(unordmapTrans, cstr_str(j.ref));
if (v)
@@ -285,7 +285,7 @@ void benchmark(
stopwatch.start("Trans Unord Map with string_view");
for (size_t i = 0; i < MAX_LOOP; ++i)
{
- c_FOREACH (j, cvec_sv, *vec_stringview)
+ c_foreach (j, cvec_sv, *vec_stringview)
{
const cmap_ssv_value* v = cmap_ssv_get(unordmapSview, *j.ref);
if (v)
diff --git a/misc/benchmarks/misc/string_bench_STD.cpp b/misc/benchmarks/misc/string_bench_STD.cpp
index 68065923..8bb87937 100644
--- a/misc/benchmarks/misc/string_bench_STD.cpp
+++ b/misc/benchmarks/misc/string_bench_STD.cpp
@@ -16,8 +16,8 @@
std::vector<std::string> read_file(const char* name)
{
std::vector<std::string> data;
- c_AUTO (cstr, line)
- c_WITH (FILE* f = fopen(name, "r"), fclose(f))
+ c_auto (cstr, line)
+ c_with (FILE* f = fopen(name, "r"), fclose(f))
while (cstr_getline(&line, f))
data.emplace_back(cstr_str(&line));
return data;
diff --git a/misc/benchmarks/picobench/picobench_cmap.cpp b/misc/benchmarks/picobench/picobench_cmap.cpp
index 9cc96d46..3ffba5b9 100644
--- a/misc/benchmarks/picobench/picobench_cmap.cpp
+++ b/misc/benchmarks/picobench/picobench_cmap.cpp
@@ -57,14 +57,14 @@ static void ins_and_erase_i(picobench::state& s)
csrandom(seed);
picobench::scope scope(s);
- c_FORRANGE (s.iterations())
+ c_forrange (s.iterations())
map[crandom()];
map.clear();
csrandom(seed);
- c_FORRANGE (s.iterations())
+ c_forrange (s.iterations())
map[crandom()];
csrandom(seed);
- c_FORRANGE (s.iterations())
+ c_forrange (s.iterations())
map.erase(crandom());
s.set_result(map.size());
}
@@ -75,14 +75,14 @@ static void ins_and_erase_cmap_i(picobench::state& s)
csrandom(seed);
picobench::scope scope(s);
- c_FORRANGE (s.iterations())
+ c_forrange (s.iterations())
cmap_i_insert(&map, crandom(), 0);
cmap_i_clear(&map);
csrandom(seed);
- c_FORRANGE (s.iterations())
+ c_forrange (s.iterations())
cmap_i_insert(&map, crandom(), 0);
csrandom(seed);
- c_FORRANGE (s.iterations())
+ c_forrange (s.iterations())
cmap_i_erase(&map, crandom());
s.set_result(cmap_i_size(&map));
cmap_i_drop(&map);
@@ -94,14 +94,14 @@ static void ins_and_erase_cmap_x(picobench::state& s)
csrandom(seed);
picobench::scope scope(s);
- c_FORRANGE (s.iterations())
+ c_forrange (s.iterations())
cmap_x_insert(&map, crandom(), 0);
cmap_x_clear(&map);
csrandom(seed);
- c_FORRANGE (s.iterations())
+ c_forrange (s.iterations())
cmap_x_insert(&map, crandom(), 0);
csrandom(seed);
- c_FORRANGE (s.iterations())
+ c_forrange (s.iterations())
cmap_x_erase(&map, crandom());
s.set_result(cmap_x_size(&map));
cmap_x_drop(&map);
@@ -127,7 +127,7 @@ static void ins_and_access_i(picobench::state& s)
csrandom(seed);
picobench::scope scope(s);
- c_FORRANGE (N1)
+ c_forrange (N1)
result += ++map[crandom() & mask];
s.set_result(result);
}
@@ -140,7 +140,7 @@ static void ins_and_access_cmap_i(picobench::state& s)
csrandom(seed);
picobench::scope scope(s);
- c_FORRANGE (N1)
+ c_forrange (N1)
result += ++cmap_i_insert(&map, crandom() & mask, 0).ref->second;
s.set_result(result);
cmap_i_drop(&map);
@@ -174,7 +174,7 @@ static void ins_and_access_s(picobench::state& s)
csrandom(seed);
picobench::scope scope(s);
- c_FORRANGE (s.iterations()) {
+ c_forrange (s.iterations()) {
randomize(&str[0], str.size());
map.emplace(str, str);
randomize(&str[0], str.size());
@@ -192,7 +192,7 @@ static void ins_and_access_cmap_s(picobench::state& s)
csrandom(seed);
picobench::scope scope(s);
- c_FORRANGE (s.iterations()) {
+ c_forrange (s.iterations()) {
randomize(buf, s.arg());
//if (s.arg() > 30) { printf("%s\n", buf); exit(0); }
cmap_str_emplace(&map, buf, buf);
@@ -227,7 +227,7 @@ static void iterate_x(picobench::state& s)
size_t result = 0;
// measure insert then iterate whole map
- c_FORRANGE (n, s.iterations()) {
+ c_forrange (n, s.iterations()) {
map[crandom()] = n;
if (!(n & K)) for (auto const& keyVal : map)
result += keyVal.second;
@@ -237,7 +237,7 @@ static void iterate_x(picobench::state& s)
csrandom(seed);
// measure erase then iterate whole map
- c_FORRANGE (n, s.iterations()) {
+ c_forrange (n, s.iterations()) {
map.erase(crandom());
if (!(n & K)) for (auto const& keyVal : map)
result += keyVal.second;
@@ -255,9 +255,9 @@ static void iterate_cmap_x(picobench::state& s)
size_t result = 0;
// measure insert then iterate whole map
- c_FORRANGE (n, s.iterations()) {
+ c_forrange (n, s.iterations()) {
cmap_x_insert_or_assign(&map, crandom(), n);
- if (!(n & K)) c_FOREACH (i, cmap_x, map)
+ if (!(n & K)) c_foreach (i, cmap_x, map)
result += i.ref->second;
}
@@ -265,9 +265,9 @@ static void iterate_cmap_x(picobench::state& s)
csrandom(seed);
// measure erase then iterate whole map
- c_FORRANGE (n, s.iterations()) {
+ c_forrange (n, s.iterations()) {
cmap_x_erase(&map, crandom());
- if (!(n & K)) c_FOREACH (i, cmap_x, map)
+ if (!(n & K)) c_foreach (i, cmap_x, map)
result += i.ref->second;
}
s.set_result(result);
diff --git a/misc/benchmarks/picobench/picobench_csmap.cpp b/misc/benchmarks/picobench/picobench_csmap.cpp
index 9ad8f9cd..5caab6cc 100644
--- a/misc/benchmarks/picobench/picobench_csmap.cpp
+++ b/misc/benchmarks/picobench/picobench_csmap.cpp
@@ -38,7 +38,7 @@ static void ctor_and_ins_one_i(picobench::state& s)
{
size_t result = 0;
picobench::scope scope(s);
- c_FORRANGE (n, s.iterations()) {
+ c_forrange (n, s.iterations()) {
MapInt map;
map[n];
result += map.size();
@@ -50,7 +50,7 @@ static void ctor_and_ins_one_csmap_i(picobench::state& s)
{
size_t result = 0;
picobench::scope scope(s);
- c_FORRANGE (n, s.iterations()) {
+ c_forrange (n, s.iterations()) {
csmap_i map = csmap_i_init();
csmap_i_insert(&map, n, 0);
result += csmap_i_size(&map);
@@ -73,7 +73,7 @@ static void insert_i(picobench::state& s)
MapInt map;
csrandom(seed);
picobench::scope scope(s);
- c_FORRANGE (n, s.iterations())
+ c_forrange (n, s.iterations())
map.emplace(crandom() & 0xfffffff, n);
s.set_result(map.size());
}
@@ -83,7 +83,7 @@ static void insert_csmap_i(picobench::state& s)
csmap_i map = csmap_i_init();
csrandom(seed);
picobench::scope scope(s);
- c_FORRANGE (n, s.iterations())
+ c_forrange (n, s.iterations())
csmap_i_insert(&map, crandom() & 0xfffffff, n);
s.set_result(csmap_i_size(&map));
csmap_i_drop(&map);
@@ -106,17 +106,17 @@ static void ins_and_erase_i(picobench::state& s)
csrandom(seed);
picobench::scope scope(s);
- c_FORRANGE (i, s.iterations())
+ c_forrange (i, s.iterations())
map.emplace(crandom() & mask, i);
result = map.size();
map.clear();
csrandom(seed);
- c_FORRANGE (i, s.iterations())
+ c_forrange (i, s.iterations())
map[crandom() & mask] = i;
csrandom(seed);
- c_FORRANGE (s.iterations())
+ c_forrange (s.iterations())
map.erase(crandom() & mask);
s.set_result(result);
}
@@ -129,17 +129,17 @@ static void ins_and_erase_csmap_i(picobench::state& s)
csrandom(seed);
picobench::scope scope(s);
- c_FORRANGE (i, s.iterations())
+ c_forrange (i, s.iterations())
csmap_i_insert(&map, crandom() & mask, i);
result = csmap_i_size(&map);
csmap_i_clear(&map);
csrandom(seed);
- c_FORRANGE (i, s.iterations())
+ c_forrange (i, s.iterations())
csmap_i_insert_or_assign(&map, crandom() & mask, i);
csrandom(seed);
- c_FORRANGE (s.iterations())
+ c_forrange (s.iterations())
csmap_i_erase(&map, crandom() & mask);
s.set_result(result);
csmap_i_drop(&map);
@@ -161,7 +161,7 @@ static void ins_and_access_i(picobench::state& s)
csrandom(seed);
picobench::scope scope(s);
- c_FORRANGE (s.iterations()) {
+ c_forrange (s.iterations()) {
result += ++map[crandom() & mask];
auto it = map.find(crandom() & mask);
if (it != map.end()) map.erase(it->first);
@@ -177,7 +177,7 @@ static void ins_and_access_csmap_i(picobench::state& s)
csrandom(seed);
picobench::scope scope(s);
- c_FORRANGE (s.iterations()) {
+ c_forrange (s.iterations()) {
result += ++csmap_i_insert(&map, crandom() & mask, 0).ref->second;
const csmap_i_value* val = csmap_i_get(&map, crandom() & mask);
if (val) csmap_i_erase(&map, val->first);
@@ -208,12 +208,12 @@ static void ins_and_access_s(picobench::state& s)
picobench::scope scope(s);
csrandom(seed);
- c_FORRANGE (s.iterations()) {
+ c_forrange (s.iterations()) {
randomize(&str[0], str.size());
map.emplace(str, str);
}
csrandom(seed);
- c_FORRANGE (s.iterations()) {
+ c_forrange (s.iterations()) {
randomize(&str[0], str.size());
result += map.erase(str);
}
@@ -229,12 +229,12 @@ static void ins_and_access_csmap_s(picobench::state& s)
picobench::scope scope(s);
csrandom(seed);
- c_FORRANGE (s.iterations()) {
+ c_forrange (s.iterations()) {
randomize(buf, s.arg());
csmap_str_emplace(&map, buf, buf);
}
csrandom(seed);
- c_FORRANGE (s.iterations()) {
+ c_forrange (s.iterations()) {
randomize(buf, s.arg());
result += csmap_str_erase(&map, buf);
/*csmap_str_iter it = csmap_str_find(&map, buf);
@@ -266,7 +266,7 @@ static void iterate_x(picobench::state& s)
size_t result = 0;
// measure insert then iterate whole map
- c_FORRANGE (n, s.iterations()) {
+ c_forrange (n, s.iterations()) {
map[crandom()] = n;
if (!(n & K)) for (auto const& keyVal : map)
result += keyVal.second;
@@ -276,7 +276,7 @@ static void iterate_x(picobench::state& s)
csrandom(seed);
// measure erase then iterate whole map
- c_FORRANGE (n, s.iterations()) {
+ c_forrange (n, s.iterations()) {
map.erase(crandom());
if (!(n & K)) for (auto const& keyVal : map)
result += keyVal.second;
@@ -294,9 +294,9 @@ static void iterate_csmap_x(picobench::state& s)
size_t result = 0;
// measure insert then iterate whole map
- c_FORRANGE (n, s.iterations()) {
+ c_forrange (n, s.iterations()) {
csmap_x_insert_or_assign(&map, crandom(), n);
- if (!(n & K)) c_FOREACH (i, csmap_x, map)
+ if (!(n & K)) c_foreach (i, csmap_x, map)
result += i.ref->second;
}
@@ -304,9 +304,9 @@ static void iterate_csmap_x(picobench::state& s)
csrandom(seed);
// measure erase then iterate whole map
- c_FORRANGE (n, s.iterations()) {
+ c_forrange (n, s.iterations()) {
csmap_x_erase(&map, crandom());
- if (!(n & K)) c_FOREACH (i, csmap_x, map)
+ if (!(n & K)) c_foreach (i, csmap_x, map)
result += i.ref->second;
}
s.set_result(result);
diff --git a/misc/benchmarks/plotbench/cdeq_benchmark.cpp b/misc/benchmarks/plotbench/cdeq_benchmark.cpp
index ed463ee4..1259cc07 100644
--- a/misc/benchmarks/plotbench/cdeq_benchmark.cpp
+++ b/misc/benchmarks/plotbench/cdeq_benchmark.cpp
@@ -29,29 +29,29 @@ Sample test_std_deque() {
s.test[INSERT].t1 = clock();
container con;
csrandom(seed);
- c_FORRANGE (N/3) con.push_front(crandom() & mask1);
- c_FORRANGE (N/3) {con.push_back(crandom() & mask1); con.pop_front();}
- c_FORRANGE (N/3) con.push_back(crandom() & mask1);
+ c_forrange (N/3) con.push_front(crandom() & mask1);
+ c_forrange (N/3) {con.push_back(crandom() & mask1); con.pop_front();}
+ c_forrange (N/3) con.push_back(crandom() & mask1);
s.test[INSERT].t2 = clock();
s.test[INSERT].sum = con.size();
s.test[ERASE].t1 = clock();
- c_FORRANGE (con.size()/2) { con.pop_front(); con.pop_back(); }
+ c_forrange (con.size()/2) { con.pop_front(); con.pop_back(); }
s.test[ERASE].t2 = clock();
s.test[ERASE].sum = con.size();
}{
container con;
csrandom(seed);
- c_FORRANGE (N) con.push_back(crandom() & mask2);
+ c_forrange (N) con.push_back(crandom() & mask2);
s.test[FIND].t1 = clock();
size_t sum = 0;
// Iteration - not inherent find - skipping
//container::iterator it;
- //c_FORRANGE (S) if ((it = std::find(con.begin(), con.end(), crandom() & mask2)) != con.end()) sum += *it;
+ //c_forrange (S) if ((it = std::find(con.begin(), con.end(), crandom() & mask2)) != con.end()) sum += *it;
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
s.test[ITER].t1 = clock();
sum = 0;
- c_FORRANGE (R) c_FORRANGE (i, N) sum += con[i];
+ c_forrange (R) c_forrange (i, N) sum += con[i];
s.test[ITER].t2 = clock();
s.test[ITER].sum = sum;
s.test[DESTRUCT].t1 = clock();
@@ -73,29 +73,29 @@ Sample test_stc_deque() {
container con = cdeq_x_init();
//cdeq_x_reserve(&con, N);
csrandom(seed);
- c_FORRANGE (N/3) cdeq_x_push_front(&con, crandom() & mask1);
- c_FORRANGE (N/3) {cdeq_x_push_back(&con, crandom() & mask1); cdeq_x_pop_front(&con);}
- c_FORRANGE (N/3) cdeq_x_push_back(&con, crandom() & mask1);
+ c_forrange (N/3) cdeq_x_push_front(&con, crandom() & mask1);
+ c_forrange (N/3) {cdeq_x_push_back(&con, crandom() & mask1); cdeq_x_pop_front(&con);}
+ c_forrange (N/3) cdeq_x_push_back(&con, crandom() & mask1);
s.test[INSERT].t2 = clock();
s.test[INSERT].sum = cdeq_x_size(&con);
s.test[ERASE].t1 = clock();
- c_FORRANGE (cdeq_x_size(&con)/2) { cdeq_x_pop_front(&con); cdeq_x_pop_back(&con); }
+ c_forrange (cdeq_x_size(&con)/2) { cdeq_x_pop_front(&con); cdeq_x_pop_back(&con); }
s.test[ERASE].t2 = clock();
s.test[ERASE].sum = cdeq_x_size(&con);
cdeq_x_drop(&con);
}{
csrandom(seed);
container con = cdeq_x_init();
- c_FORRANGE (N) cdeq_x_push_back(&con, crandom() & mask2);
+ c_forrange (N) cdeq_x_push_back(&con, crandom() & mask2);
s.test[FIND].t1 = clock();
size_t sum = 0;
//cdeq_x_iter it, end = cdeq_x_end(&con);
- //c_FORRANGE (S) if ((it = cdeq_x_find(&con, crandom() & mask2)).ref != end.ref) sum += *it.ref;
+ //c_forrange (S) if ((it = cdeq_x_find(&con, crandom() & mask2)).ref != end.ref) sum += *it.ref;
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
s.test[ITER].t1 = clock();
sum = 0;
- c_FORRANGE (R) c_FORRANGE (i, N) sum += con.data[i];
+ c_forrange (R) c_forrange (i, N) sum += con.data[i];
s.test[ITER].t2 = clock();
s.test[ITER].sum = sum;
s.test[DESTRUCT].t1 = clock();
@@ -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, SAMPLES) {
+ c_forrange (i, SAMPLES) {
std_s[i] = test_std_deque();
stc_s[i] = test_stc_deque();
- if (i > 0) c_FORRANGE (j, N_TESTS) {
+ if (i > 0) c_forrange (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 %lld, sample %lld\n", i, j);
@@ -122,17 +122,17 @@ int main(int argc, char* argv[])
bool header = (argc > 2 && argv[2][0] == '1');
float std_sum = 0, stc_sum = 0;
- c_FORRANGE (j, N_TESTS) {
+ c_forrange (j, N_TESTS) {
std_sum += secs(std_s[0].test[j]);
stc_sum += secs(stc_s[0].test[j]);
}
if (header) printf("Compiler,Library,C,Method,Seconds,Ratio\n");
- c_FORRANGE (j, N_TESTS)
+ c_forrange (j, N_TESTS)
printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, std_s[0].name, N, operations[j], secs(std_s[0].test[j]), 1.0f);
printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, std_s[0].name, N, "total", std_sum, 1.0f);
- c_FORRANGE (j, N_TESTS)
+ c_forrange (j, N_TESTS)
printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, stc_s[0].name, N, operations[j], secs(stc_s[0].test[j]), secs(std_s[0].test[j]) ? secs(stc_s[0].test[j])/secs(std_s[0].test[j]) : 1.0f);
printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, stc_s[0].name, N, "total", stc_sum, stc_sum/std_sum);
}
diff --git a/misc/benchmarks/plotbench/clist_benchmark.cpp b/misc/benchmarks/plotbench/clist_benchmark.cpp
index aac61ebf..04c8e8cd 100644
--- a/misc/benchmarks/plotbench/clist_benchmark.cpp
+++ b/misc/benchmarks/plotbench/clist_benchmark.cpp
@@ -29,28 +29,28 @@ Sample test_std_forward_list() {
s.test[INSERT].t1 = clock();
container con;
csrandom(seed);
- c_FORRANGE (N/2) con.push_front(crandom() & mask1);
- c_FORRANGE (N/2) con.push_front(crandom() & mask1);
+ c_forrange (N/2) con.push_front(crandom() & mask1);
+ c_forrange (N/2) con.push_front(crandom() & mask1);
s.test[INSERT].t2 = clock();
s.test[INSERT].sum = 0;
s.test[ERASE].t1 = clock();
- c_FORRANGE (N) con.pop_front();
+ c_forrange (N) con.pop_front();
s.test[ERASE].t2 = clock();
s.test[ERASE].sum = 0;
}{
container con;
csrandom(seed);
- c_FORRANGE (N) con.push_front(crandom() & mask2);
+ c_forrange (N) con.push_front(crandom() & mask2);
s.test[FIND].t1 = clock();
size_t sum = 0;
container::iterator it;
// Iteration - not inherent find - skipping
- //c_FORRANGE (S) if ((it = std::find(con.begin(), con.end(), crandom() & mask2)) != con.end()) sum += *it;
+ //c_forrange (S) if ((it = std::find(con.begin(), con.end(), crandom() & mask2)) != con.end()) sum += *it;
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
s.test[ITER].t1 = clock();
sum = 0;
- c_FORRANGE (R) for (auto i: con) sum += i;
+ c_forrange (R) for (auto i: con) sum += i;
s.test[ITER].t2 = clock();
s.test[ITER].sum = sum;
s.test[DESTRUCT].t1 = clock();
@@ -71,28 +71,28 @@ Sample test_stc_forward_list() {
s.test[INSERT].t1 = clock();
container con = clist_x_init();
csrandom(seed);
- c_FORRANGE (N/2) clist_x_push_front(&con, crandom() & mask1);
- c_FORRANGE (N/2) clist_x_push_back(&con, crandom() & mask1);
+ c_forrange (N/2) clist_x_push_front(&con, crandom() & mask1);
+ c_forrange (N/2) clist_x_push_back(&con, crandom() & mask1);
s.test[INSERT].t2 = clock();
s.test[INSERT].sum = 0;
s.test[ERASE].t1 = clock();
- c_FORRANGE (N) clist_x_pop_front(&con);
+ c_forrange (N) clist_x_pop_front(&con);
s.test[ERASE].t2 = clock();
s.test[ERASE].sum = 0;
clist_x_drop(&con);
}{
csrandom(seed);
container con = clist_x_init();
- c_FORRANGE (N) clist_x_push_front(&con, crandom() & mask2);
+ c_forrange (N) clist_x_push_front(&con, crandom() & mask2);
s.test[FIND].t1 = clock();
size_t sum = 0;
//clist_x_iter it, end = clist_x_end(&con);
- //c_FORRANGE (S) if ((it = clist_x_find(&con, crandom() & mask2)).ref != end.ref) sum += *it.ref;
+ //c_forrange (S) if ((it = clist_x_find(&con, crandom() & mask2)).ref != end.ref) sum += *it.ref;
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
s.test[ITER].t1 = clock();
sum = 0;
- c_FORRANGE (R) c_FOREACH (i, clist_x, con) sum += *i.ref;
+ c_forrange (R) c_foreach (i, clist_x, con) sum += *i.ref;
s.test[ITER].t2 = clock();
s.test[ITER].sum = sum;
s.test[DESTRUCT].t1 = clock();
@@ -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, SAMPLES) {
+ c_forrange (i, SAMPLES) {
std_s[i] = test_std_forward_list();
stc_s[i] = test_stc_forward_list();
- if (i > 0) c_FORRANGE (j, N_TESTS) {
+ if (i > 0) c_forrange (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 %lld, sample %lld\n", i, j);
@@ -119,17 +119,17 @@ int main(int argc, char* argv[])
bool header = (argc > 2 && argv[2][0] == '1');
float std_sum = 0, stc_sum = 0;
- c_FORRANGE (j, N_TESTS) {
+ c_forrange (j, N_TESTS) {
std_sum += secs(std_s[0].test[j]);
stc_sum += secs(stc_s[0].test[j]);
}
if (header) printf("Compiler,Library,C,Method,Seconds,Ratio\n");
- c_FORRANGE (j, N_TESTS)
+ c_forrange (j, N_TESTS)
printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, std_s[0].name, N, operations[j], secs(std_s[0].test[j]), 1.0f);
printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, std_s[0].name, N, "total", std_sum, 1.0f);
- c_FORRANGE (j, N_TESTS)
+ c_forrange (j, N_TESTS)
printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, stc_s[0].name, N, operations[j], secs(stc_s[0].test[j]), secs(std_s[0].test[j]) ? secs(stc_s[0].test[j])/secs(std_s[0].test[j]) : 1.0f);
printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, stc_s[0].name, N, "total", stc_sum, stc_sum/std_sum);
} \ No newline at end of file
diff --git a/misc/benchmarks/plotbench/cmap_benchmark.cpp b/misc/benchmarks/plotbench/cmap_benchmark.cpp
index 095b5513..7a8f29d2 100644
--- a/misc/benchmarks/plotbench/cmap_benchmark.cpp
+++ b/misc/benchmarks/plotbench/cmap_benchmark.cpp
@@ -29,30 +29,30 @@ Sample test_std_unordered_map() {
csrandom(seed);
s.test[INSERT].t1 = clock();
container con;
- c_FORRANGE (i, N/2) con.emplace(crandom() & mask1, i);
- c_FORRANGE (i, N/2) con.emplace(i, i);
+ c_forrange (i, N/2) con.emplace(crandom() & mask1, i);
+ c_forrange (i, N/2) con.emplace(i, i);
s.test[INSERT].t2 = clock();
s.test[INSERT].sum = con.size();
csrandom(seed);
s.test[ERASE].t1 = clock();
- c_FORRANGE (N) con.erase(crandom() & mask1);
+ c_forrange (N) con.erase(crandom() & mask1);
s.test[ERASE].t2 = clock();
s.test[ERASE].sum = con.size();
}{
container con;
csrandom(seed);
- c_FORRANGE (i, N/2) con.emplace(crandom() & mask1, i);
- c_FORRANGE (i, N/2) con.emplace(i, i);
+ c_forrange (i, N/2) con.emplace(crandom() & mask1, i);
+ c_forrange (i, N/2) con.emplace(i, i);
csrandom(seed);
s.test[FIND].t1 = clock();
size_t sum = 0;
container::iterator it;
- c_FORRANGE (N) if ((it = con.find(crandom() & mask1)) != con.end()) sum += it->second;
+ c_forrange (N) if ((it = con.find(crandom() & mask1)) != con.end()) sum += it->second;
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
s.test[ITER].t1 = clock();
sum = 0;
- c_FORRANGE (R) for (auto i: con) sum += i.second;
+ c_forrange (R) for (auto i: con) sum += i.second;
s.test[ITER].t2 = clock();
s.test[ITER].sum = sum;
s.test[DESTRUCT].t1 = clock();
@@ -73,33 +73,33 @@ Sample test_stc_unordered_map() {
csrandom(seed);
s.test[INSERT].t1 = clock();
container con = cmap_x_init();
- c_FORRANGE (i, N/2) cmap_x_insert(&con, crandom() & mask1, i);
- c_FORRANGE (i, N/2) cmap_x_insert(&con, i, i);
+ c_forrange (i, N/2) cmap_x_insert(&con, crandom() & mask1, i);
+ c_forrange (i, N/2) cmap_x_insert(&con, i, i);
s.test[INSERT].t2 = clock();
s.test[INSERT].sum = cmap_x_size(&con);
csrandom(seed);
s.test[ERASE].t1 = clock();
- c_FORRANGE (N) cmap_x_erase(&con, crandom() & mask1);
+ c_forrange (N) cmap_x_erase(&con, crandom() & mask1);
s.test[ERASE].t2 = clock();
s.test[ERASE].sum = cmap_x_size(&con);
cmap_x_drop(&con);
}{
container con = cmap_x_init();
csrandom(seed);
- c_FORRANGE (i, N/2) cmap_x_insert(&con, crandom() & mask1, i);
- c_FORRANGE (i, N/2) cmap_x_insert(&con, i, i);
+ c_forrange (i, N/2) cmap_x_insert(&con, crandom() & mask1, i);
+ c_forrange (i, N/2) cmap_x_insert(&con, i, i);
csrandom(seed);
s.test[FIND].t1 = clock();
size_t sum = 0;
const cmap_x_value* val;
- c_FORRANGE (N)
+ c_forrange (N)
if ((val = cmap_x_get(&con, crandom() & mask1)))
sum += val->second;
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
s.test[ITER].t1 = clock();
sum = 0;
- c_FORRANGE (R) c_FOREACH (i, cmap_x, con) sum += i.ref->second;
+ c_forrange (R) c_foreach (i, cmap_x, con) sum += i.ref->second;
s.test[ITER].t2 = clock();
s.test[ITER].sum = sum;
s.test[DESTRUCT].t1 = clock();
@@ -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, SAMPLES) {
+ c_forrange (i, SAMPLES) {
std_s[i] = test_std_unordered_map();
stc_s[i] = test_stc_unordered_map();
- if (i > 0) c_FORRANGE (j, N_TESTS) {
+ if (i > 0) c_forrange (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 %lld, sample %lld\n", i, j);
@@ -126,17 +126,17 @@ int main(int argc, char* argv[])
bool header = (argc > 2 && argv[2][0] == '1');
float std_sum = 0, stc_sum = 0;
- c_FORRANGE (j, N_TESTS) {
+ c_forrange (j, N_TESTS) {
std_sum += secs(std_s[0].test[j]);
stc_sum += secs(stc_s[0].test[j]);
}
if (header) printf("Compiler,Library,C,Method,Seconds,Ratio\n");
- c_FORRANGE (j, N_TESTS)
+ c_forrange (j, N_TESTS)
printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, std_s[0].name, N, operations[j], secs(std_s[0].test[j]), 1.0f);
printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, std_s[0].name, N, "total", std_sum, 1.0f);
- c_FORRANGE (j, N_TESTS)
+ c_forrange (j, N_TESTS)
printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, stc_s[0].name, N, operations[j], secs(stc_s[0].test[j]), secs(std_s[0].test[j]) ? secs(stc_s[0].test[j])/secs(std_s[0].test[j]) : 1.0f);
printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, stc_s[0].name, N, "total", stc_sum, stc_sum/std_sum);
} \ No newline at end of file
diff --git a/misc/benchmarks/plotbench/cpque_benchmark.cpp b/misc/benchmarks/plotbench/cpque_benchmark.cpp
index f2a85aee..a729c09f 100644
--- a/misc/benchmarks/plotbench/cpque_benchmark.cpp
+++ b/misc/benchmarks/plotbench/cpque_benchmark.cpp
@@ -20,14 +20,14 @@ void std_test()
std::priority_queue<float, std::vector<float>, std::greater<float>> pq;
rng = stc64_new(seed);
clock_t start = clock();
- c_FORRANGE (i, N)
+ c_forrange (i, N)
pq.push((float) stc64_randf(&rng)*100000);
printf("Built priority queue: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC);
printf("%g ", pq.top());
start = clock();
- c_FORRANGE (i, N) {
+ c_forrange (i, N) {
pq.pop();
}
@@ -40,22 +40,22 @@ void stc_test()
stc64_t rng;
int N = 10000000, M = 10;
- c_AUTO (cpque_f, pq)
+ c_auto (cpque_f, pq)
{
rng = stc64_new(seed);
clock_t start = clock();
- c_FORRANGE (i, N)
+ c_forrange (i, N)
cpque_f_push(&pq, (float) stc64_randf(&rng)*100000);
printf("Built priority queue: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC);
printf("%g ", *cpque_f_top(&pq));
- c_FORRANGE (i, M) {
+ c_forrange (i, M) {
cpque_f_pop(&pq);
}
start = clock();
- c_FORRANGE (i, M, N)
+ c_forrange (i, M, N)
cpque_f_pop(&pq);
printf("\npopped PQ: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC);
}
diff --git a/misc/benchmarks/plotbench/csmap_benchmark.cpp b/misc/benchmarks/plotbench/csmap_benchmark.cpp
index 7dec8368..46bd695c 100644
--- a/misc/benchmarks/plotbench/csmap_benchmark.cpp
+++ b/misc/benchmarks/plotbench/csmap_benchmark.cpp
@@ -29,30 +29,30 @@ Sample test_std_map() {
csrandom(seed);
s.test[INSERT].t1 = clock();
container con;
- c_FORRANGE (i, N/2) con.emplace(crandom() & mask1, i);
- c_FORRANGE (i, N/2) con.emplace(i, i);
+ c_forrange (i, N/2) con.emplace(crandom() & mask1, i);
+ c_forrange (i, N/2) con.emplace(i, i);
s.test[INSERT].t2 = clock();
s.test[INSERT].sum = con.size();
csrandom(seed);
s.test[ERASE].t1 = clock();
- c_FORRANGE (N) con.erase(crandom() & mask1);
+ c_forrange (N) con.erase(crandom() & mask1);
s.test[ERASE].t2 = clock();
s.test[ERASE].sum = con.size();
}{
container con;
csrandom(seed);
- c_FORRANGE (i, N/2) con.emplace(crandom() & mask1, i);
- c_FORRANGE (i, N/2) con.emplace(i, i);
+ c_forrange (i, N/2) con.emplace(crandom() & mask1, i);
+ c_forrange (i, N/2) con.emplace(i, i);
csrandom(seed);
s.test[FIND].t1 = clock();
size_t sum = 0;
container::iterator it;
- c_FORRANGE (N) if ((it = con.find(crandom() & mask1)) != con.end()) sum += it->second;
+ c_forrange (N) if ((it = con.find(crandom() & mask1)) != con.end()) sum += it->second;
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
s.test[ITER].t1 = clock();
sum = 0;
- c_FORRANGE (R) for (auto i: con) sum += i.second;
+ c_forrange (R) for (auto i: con) sum += i.second;
s.test[ITER].t2 = clock();
s.test[ITER].sum = sum;
s.test[DESTRUCT].t1 = clock();
@@ -74,33 +74,33 @@ Sample test_stc_map() {
csrandom(seed);
s.test[INSERT].t1 = clock();
container con = csmap_x_init();
- c_FORRANGE (i, N/2) csmap_x_insert(&con, crandom() & mask1, i);
- c_FORRANGE (i, N/2) csmap_x_insert(&con, i, i);
+ c_forrange (i, N/2) csmap_x_insert(&con, crandom() & mask1, i);
+ c_forrange (i, N/2) csmap_x_insert(&con, i, i);
s.test[INSERT].t2 = clock();
s.test[INSERT].sum = csmap_x_size(&con);
csrandom(seed);
s.test[ERASE].t1 = clock();
- c_FORRANGE (N) csmap_x_erase(&con, crandom() & mask1);
+ c_forrange (N) csmap_x_erase(&con, crandom() & mask1);
s.test[ERASE].t2 = clock();
s.test[ERASE].sum = csmap_x_size(&con);
csmap_x_drop(&con);
}{
container con = csmap_x_init();
csrandom(seed);
- c_FORRANGE (i, N/2) csmap_x_insert(&con, crandom() & mask1, i);
- c_FORRANGE (i, N/2) csmap_x_insert(&con, i, i);
+ c_forrange (i, N/2) csmap_x_insert(&con, crandom() & mask1, i);
+ c_forrange (i, N/2) csmap_x_insert(&con, i, i);
csrandom(seed);
s.test[FIND].t1 = clock();
size_t sum = 0;
const csmap_x_value* val;
- c_FORRANGE (N)
+ c_forrange (N)
if ((val = csmap_x_get(&con, crandom() & mask1)))
sum += val->second;
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
s.test[ITER].t1 = clock();
sum = 0;
- c_FORRANGE (R) c_FOREACH (i, csmap_x, con) sum += i.ref->second;
+ c_forrange (R) c_foreach (i, csmap_x, con) sum += i.ref->second;
s.test[ITER].t2 = clock();
s.test[ITER].sum = sum;
s.test[DESTRUCT].t1 = clock();
@@ -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, SAMPLES) {
+ c_forrange (i, SAMPLES) {
std_s[i] = test_std_map();
stc_s[i] = test_stc_map();
- if (i > 0) c_FORRANGE (j, N_TESTS) {
+ if (i > 0) c_forrange (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 %lld, sample %lld\n", i, j);
@@ -127,17 +127,17 @@ int main(int argc, char* argv[])
bool header = (argc > 2 && argv[2][0] == '1');
float std_sum = 0, stc_sum = 0;
- c_FORRANGE (j, N_TESTS) {
+ c_forrange (j, N_TESTS) {
std_sum += secs(std_s[0].test[j]);
stc_sum += secs(stc_s[0].test[j]);
}
if (header) printf("Compiler,Library,C,Method,Seconds,Ratio\n");
- c_FORRANGE (j, N_TESTS)
+ c_forrange (j, N_TESTS)
printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, std_s[0].name, N, operations[j], secs(std_s[0].test[j]), 1.0f);
printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, std_s[0].name, N, "total", std_sum, 1.0f);
- c_FORRANGE (j, N_TESTS)
+ c_forrange (j, N_TESTS)
printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, stc_s[0].name, N, operations[j], secs(stc_s[0].test[j]), secs(std_s[0].test[j]) ? secs(stc_s[0].test[j])/secs(std_s[0].test[j]) : 1.0f);
printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, stc_s[0].name, N, "total", stc_sum, stc_sum/std_sum);
}
diff --git a/misc/benchmarks/plotbench/cvec_benchmark.cpp b/misc/benchmarks/plotbench/cvec_benchmark.cpp
index 466c7ff2..fe7e09fb 100644
--- a/misc/benchmarks/plotbench/cvec_benchmark.cpp
+++ b/misc/benchmarks/plotbench/cvec_benchmark.cpp
@@ -29,27 +29,27 @@ Sample test_std_vector() {
s.test[INSERT].t1 = clock();
container con;
csrandom(seed);
- c_FORRANGE (N) con.push_back(crandom() & mask1);
+ c_forrange (N) con.push_back(crandom() & mask1);
s.test[INSERT].t2 = clock();
s.test[INSERT].sum = con.size();
s.test[ERASE].t1 = clock();
- c_FORRANGE (N) con.pop_back();
+ c_forrange (N) con.pop_back();
s.test[ERASE].t2 = clock();
s.test[ERASE].sum = con.size();
}{
container con;
csrandom(seed);
- c_FORRANGE (N) con.push_back(crandom() & mask2);
+ c_forrange (N) con.push_back(crandom() & mask2);
s.test[FIND].t1 = clock();
size_t sum = 0;
//container::iterator it;
// Iteration - not inherent find - skipping
- //c_FORRANGE (S) if ((it = std::find(con.begin(), con.end(), crandom() & mask2)) != con.end()) sum += *it;
+ //c_forrange (S) if ((it = std::find(con.begin(), con.end(), crandom() & mask2)) != con.end()) sum += *it;
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
s.test[ITER].t1 = clock();
sum = 0;
- c_FORRANGE (R) c_FORRANGE (i, N) sum += con[i];
+ c_forrange (R) c_forrange (i, N) sum += con[i];
s.test[ITER].t2 = clock();
s.test[ITER].sum = sum;
s.test[DESTRUCT].t1 = clock();
@@ -71,27 +71,27 @@ Sample test_stc_vector() {
s.test[INSERT].t1 = clock();
container con = cvec_x_init();
csrandom(seed);
- c_FORRANGE (N) cvec_x_push_back(&con, crandom() & mask1);
+ c_forrange (N) cvec_x_push_back(&con, crandom() & mask1);
s.test[INSERT].t2 = clock();
s.test[INSERT].sum = cvec_x_size(&con);
s.test[ERASE].t1 = clock();
- c_FORRANGE (N) { cvec_x_pop_back(&con); }
+ c_forrange (N) { cvec_x_pop_back(&con); }
s.test[ERASE].t2 = clock();
s.test[ERASE].sum = cvec_x_size(&con);
cvec_x_drop(&con);
}{
csrandom(seed);
container con = cvec_x_init();
- c_FORRANGE (N) cvec_x_push_back(&con, crandom() & mask2);
+ c_forrange (N) cvec_x_push_back(&con, crandom() & mask2);
s.test[FIND].t1 = clock();
size_t sum = 0;
//cvec_x_iter it, end = cvec_x_end(&con);
- //c_FORRANGE (S) if ((it = cvec_x_find(&con, crandom() & mask2)).ref != end.ref) sum += *it.ref;
+ //c_forrange (S) if ((it = cvec_x_find(&con, crandom() & mask2)).ref != end.ref) sum += *it.ref;
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
s.test[ITER].t1 = clock();
sum = 0;
- c_FORRANGE (R) c_FORRANGE (i, N) sum += con.data[i];
+ c_forrange (R) c_forrange (i, N) sum += con.data[i];
s.test[ITER].t2 = clock();
s.test[ITER].sum = sum;
s.test[DESTRUCT].t1 = clock();
@@ -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, SAMPLES) {
+ c_forrange (i, SAMPLES) {
std_s[i] = test_std_vector();
stc_s[i] = test_stc_vector();
- if (i > 0) c_FORRANGE (j, N_TESTS) {
+ if (i > 0) c_forrange (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 %lld, sample %lld\n", i, j);
@@ -118,17 +118,17 @@ int main(int argc, char* argv[])
bool header = (argc > 2 && argv[2][0] == '1');
float std_sum = 0, stc_sum = 0;
- c_FORRANGE (j, N_TESTS) {
+ c_forrange (j, N_TESTS) {
std_sum += secs(std_s[0].test[j]);
stc_sum += secs(stc_s[0].test[j]);
}
if (header) printf("Compiler,Library,C,Method,Seconds,Ratio\n");
- c_FORRANGE (j, N_TESTS)
+ c_forrange (j, N_TESTS)
printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, std_s[0].name, N, operations[j], secs(std_s[0].test[j]), 1.0f);
printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, std_s[0].name, N, "total", std_sum, 1.0f);
- c_FORRANGE (j, N_TESTS)
+ c_forrange (j, N_TESTS)
printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, stc_s[0].name, N, operations[j], secs(stc_s[0].test[j]), secs(std_s[0].test[j]) ? secs(stc_s[0].test[j])/secs(std_s[0].test[j]) : 1.0f);
printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, stc_s[0].name, N, "total", stc_sum, stc_sum/std_sum);
}
diff --git a/misc/benchmarks/shootout_hashmaps.cpp b/misc/benchmarks/shootout_hashmaps.cpp
index 7c5095f6..78d7bce2 100644
--- a/misc/benchmarks/shootout_hashmaps.cpp
+++ b/misc/benchmarks/shootout_hashmaps.cpp
@@ -48,7 +48,7 @@ KHASH_MAP_INIT_INT64(ii, IValue)
#define CMAP_EMPLACE(X, key, val) cmap_##X##_insert(&map, key, val).ref->second
#define CMAP_ERASE(X, key) cmap_##X##_erase(&map, key)
#define CMAP_FIND(X, key) cmap_##X##_contains(&map, key)
-#define CMAP_FOR(X, i) c_FOREACH (i, cmap_##X, map)
+#define CMAP_FOR(X, i) c_foreach (i, cmap_##X, map)
#define CMAP_ITEM(X, i) i.ref->second
#define CMAP_SIZE(X) cmap_##X##_size(&map)
#define CMAP_BUCKETS(X) cmap_##X##_bucket_count(&map)
diff --git a/misc/examples/arc_containers.c b/misc/examples/arc_containers.c
index bfe15150..201c73d5 100644
--- a/misc/examples/arc_containers.c
+++ b/misc/examples/arc_containers.c
@@ -27,8 +27,8 @@
int main()
{
- c_AUTO (Stack, stack)
- c_AUTO (List, list)
+ c_auto (Stack, stack)
+ c_auto (List, list)
{
// POPULATE stack with shared pointers to Maps:
Map *map;
@@ -64,14 +64,14 @@ int main()
puts("STACKS");
- c_FOREACH (i, Stack, stack) {
- c_FORPAIR (name, year, Map, *i.ref->get)
+ c_foreach (i, Stack, stack) {
+ c_forpair (name, year, Map, *i.ref->get)
printf(" %s:%d", cstr_str(_.name), *_.year);
puts("");
}
puts("LIST");
- c_FOREACH (i, List, list) {
- c_FORPAIR (name, year, Map, *i.ref->get)
+ c_foreach (i, List, list) {
+ c_forpair (name, year, Map, *i.ref->get)
printf(" %s:%d", cstr_str(_.name), *_.year);
puts("");
}
diff --git a/misc/examples/arc_demo.c b/misc/examples/arc_demo.c
index 564ebd6d..867cfc83 100644
--- a/misc/examples/arc_demo.c
+++ b/misc/examples/arc_demo.c
@@ -22,19 +22,19 @@ void int_drop(int* x) {
int main()
{
- c_AUTO (cvec_Arc, vec) // declare and init vec, call cvec_Arc_drop() at scope exit
- c_AUTO (csset_Arc, set) // declare and init set, call csset_Arc_drop() at scope exit
+ c_auto (cvec_Arc, vec) // declare and init vec, call cvec_Arc_drop() at scope exit
+ c_auto (csset_Arc, set) // declare and init set, call csset_Arc_drop() at scope exit
{
const int years[] = {2021, 2012, 2022, 2015};
- c_FORRANGE (i, c_ARRAYLEN(years))
+ c_forrange (i, c_ARRAYLEN(years))
cvec_Arc_push(&vec, Arc_from(years[i]));
printf("vec:");
- c_FOREACH (i, cvec_Arc, vec) printf(" %d", *i.ref->get);
+ c_foreach (i, cvec_Arc, vec) printf(" %d", *i.ref->get);
puts("");
// add odd numbers from vec to set
- c_FOREACH (i, cvec_Arc, vec)
+ c_foreach (i, cvec_Arc, vec)
if (*i.ref->get & 1)
csset_Arc_insert(&set, Arc_clone(*i.ref)); // copy shared pointer => increments counter.
@@ -43,12 +43,12 @@ int main()
cvec_Arc_pop_back(&vec);
printf("vec:");
- c_FOREACH (i, cvec_Arc, vec) printf(" %d", *i.ref->get);
+ c_foreach (i, cvec_Arc, vec) printf(" %d", *i.ref->get);
printf("\nset:");
- c_FOREACH (i, csset_Arc, set) printf(" %d", *i.ref->get);
+ c_foreach (i, csset_Arc, set) printf(" %d", *i.ref->get);
- c_WITH (Arc p = Arc_clone(vec.data[0]), Arc_drop(&p)) {
+ c_with (Arc p = Arc_clone(vec.data[0]), Arc_drop(&p)) {
printf("\n%d is now owned by %ld objects\n", *p.get, *p.use_count);
}
diff --git a/misc/examples/arcvec_erase.c b/misc/examples/arcvec_erase.c
index 8385ed65..38f11097 100644
--- a/misc/examples/arcvec_erase.c
+++ b/misc/examples/arcvec_erase.c
@@ -15,17 +15,16 @@ void show_drop(int* x) { printf("drop: %d\n", *x); }
int main()
{
- c_AUTO (Vec, vec)
+ c_auto (Vec, vec)
{
- c_FORLIST (i, int, {2012, 1990, 2012, 2019, 2015})
- Vec_emplace(&vec, *i.ref);
+ vec = c_make(Vec, {2012, 1990, 2012, 2019, 2015});
// clone the second 2012 and push it back.
// note: cloning make sure that vec.data[2] has ref count 2.
Vec_push(&vec, Arc_clone(vec.data[2]));
printf("vec before erase :");
- c_FOREACH (i, Vec, vec)
+ c_foreach (i, Vec, vec)
printf(" %d", *i.ref->get);
printf("\nerase vec.data[2]; or first matching value depending on compare.\n");
@@ -40,12 +39,12 @@ int main()
Vec_erase_at(&vec, it);
printf("vec after erase :");
- c_FOREACH (i, Vec, vec)
+ c_foreach (i, Vec, vec)
printf(" %d", *i.ref->get);
Vec_sort(&vec);
printf("\nvec after sort :");
- c_FOREACH (i, Vec, vec)
+ c_foreach (i, Vec, vec)
printf(" %d", *i.ref->get);
puts("\nDone");
diff --git a/misc/examples/astar.c b/misc/examples/astar.c
index ddc9de3a..10e45d3c 100644
--- a/misc/examples/astar.c
+++ b/misc/examples/astar.c
@@ -80,9 +80,9 @@ astar(cstr* maze, int width)
{
cdeq_point path = cdeq_point_init();
- c_AUTO (cpque_point, front)
- c_AUTO (csmap_pstep, from)
- c_AUTO (csmap_pcost, costs)
+ c_auto (cpque_point, front)
+ c_auto (csmap_pstep, from)
+ c_auto (csmap_pcost, costs)
{
point start = point_from(maze, "@", width);
point goal = point_from(maze, "!", width);
@@ -131,7 +131,7 @@ astar(cstr* maze, int width)
int
main(void)
{
- c_WITH (cstr maze = cstr_lit(
+ c_with (cstr maze = cstr_lit(
"#########################################################################\n"
"# # # # # # #\n"
"# # ######### # ##### ######### ##### ##### ##### # ! #\n"
@@ -157,9 +157,9 @@ main(void)
"#########################################################################\n"), cstr_drop(&maze))
{
int width = (int)cstr_find(&maze, "\n") + 1;
- c_WITH (cdeq_point path = astar(&maze, width), cdeq_point_drop(&path))
+ c_with (cdeq_point path = astar(&maze, width), cdeq_point_drop(&path))
{
- c_FOREACH (it, cdeq_point, path)
+ c_foreach (it, cdeq_point, path)
cstr_data(&maze)[point_index(it.ref)] = 'x';
printf("%s", cstr_str(&maze));
diff --git a/misc/examples/birthday.c b/misc/examples/birthday.c
index 63f64016..cb627ef8 100644
--- a/misc/examples/birthday.c
+++ b/misc/examples/birthday.c
@@ -18,10 +18,10 @@ static void test_repeats(void)
printf("birthday paradox: value range: 2^%d, testing repeats of 2^%d values\n", BITS, BITS_TEST);
stc64_t rng = stc64_new(seed);
- c_AUTO (cmap_ic, m)
+ c_auto (cmap_ic, m)
{
cmap_ic_reserve(&m, N);
- c_FORRANGE (i, N) {
+ c_forrange (i, N) {
uint64_t k = stc64_rand(&rng) & mask;
int v = cmap_ic_insert(&m, k, 0).ref->second += 1;
if (v > 1) printf("repeated value %" PRIu64 " (%d) at 2^%d\n",
@@ -42,17 +42,17 @@ void test_distribution(void)
stc64_t rng = stc64_new(seed);
const size_t N = 1ull << BITS ;
- c_AUTO (cmap_x, map) {
- c_FORRANGE (N) {
+ c_auto (cmap_x, map) {
+ c_forrange (N) {
uint64_t k = stc64_rand(&rng);
cmap_x_insert(&map, k & 0xf, 0).ref->second += 1;
}
uint64_t sum = 0;
- c_FOREACH (i, cmap_x, map) sum += i.ref->second;
+ c_foreach (i, cmap_x, map) sum += i.ref->second;
sum /= (uint64_t)map.size;
- c_FOREACH (i, cmap_x, map) {
+ c_foreach (i, cmap_x, map) {
printf("%4" PRIu32 ": %" PRIu64 " - %" PRIu64 ": %11.8f\n",
i.ref->first, i.ref->second, sum,
(1.0 - (double)i.ref->second / (double)sum));
diff --git a/misc/examples/bits.c b/misc/examples/bits.c
index 03b74881..730dd953 100644
--- a/misc/examples/bits.c
+++ b/misc/examples/bits.c
@@ -3,7 +3,7 @@
int main()
{
- c_WITH (cbits set = cbits_with_size(23, true), cbits_drop(&set)) {
+ c_with (cbits set = cbits_with_size(23, true), cbits_drop(&set)) {
printf("count %" c_ZI ", %" c_ZI "\n", cbits_count(&set), cbits_size(&set));
cbits s1 = cbits_from("1110100110111");
char buf[256];
@@ -16,7 +16,7 @@ int main()
printf(" str: %s\n", cbits_to_str(&set, buf, 0, 255));
printf("%4" c_ZI ": ", cbits_size(&set));
- c_FORRANGE (i, cbits_size(&set))
+ c_forrange (i, cbits_size(&set))
printf("%d", cbits_test(&set, i));
puts("");
@@ -26,34 +26,34 @@ int main()
cbits_resize(&set, 102, true);
cbits_set_value(&set, 99, false);
printf("%4" c_ZI ": ", cbits_size(&set));
- c_FORRANGE (i, cbits_size(&set))
+ c_forrange (i, cbits_size(&set))
printf("%d", cbits_test(&set, i));
puts("\nIterate:");
printf("%4" c_ZI ": ", cbits_size(&set));
- c_FORRANGE (i, cbits_size(&set))
+ c_forrange (i, cbits_size(&set))
printf("%d", cbits_test(&set, i));
puts("");
- c_WITH (cbits s2 = cbits_clone(set), cbits_drop(&s2)) {
+ c_with (cbits s2 = cbits_clone(set), cbits_drop(&s2)) {
cbits_flip_all(&s2);
cbits_set(&s2, 16);
cbits_set(&s2, 17);
cbits_set(&s2, 18);
printf(" new: ");
- c_FORRANGE (i, cbits_size(&s2))
+ c_forrange (i, cbits_size(&s2))
printf("%d", cbits_test(&s2, i));
puts("");
printf(" xor: ");
cbits_xor(&set, &s2);
- c_FORRANGE (i, cbits_size(&set))
+ c_forrange (i, cbits_size(&set))
printf("%d", cbits_test(&set, i));
puts("");
cbits_set_all(&set, false);
printf("%4" c_ZI ": ", cbits_size(&set));
- c_FORRANGE (i, cbits_size(&set))
+ c_forrange (i, cbits_size(&set))
printf("%d", cbits_test(&set, i));
puts("");
}
diff --git a/misc/examples/bits2.c b/misc/examples/bits2.c
index 9b1d1af7..b002af3c 100644
--- a/misc/examples/bits2.c
+++ b/misc/examples/bits2.c
@@ -23,19 +23,19 @@ int main()
Bits_reset(&s2, 66);
Bits_reset(&s2, 67);
printf(" s2: ");
- c_FORRANGE (i, Bits_size(&s2))
+ c_forrange (i, Bits_size(&s2))
printf("%d", Bits_test(&s2, i));
puts("");
printf("xor: ");
Bits_xor(&s1, &s2);
- c_FORRANGE (i, Bits_size(&s1))
+ c_forrange (i, Bits_size(&s1))
printf("%d", Bits_test(&s1, i));
puts("");
printf("all: ");
Bits_set_pattern(&s1, 0x3333333333333333);
- c_FORRANGE (i, Bits_size(&s1))
+ c_forrange (i, Bits_size(&s1))
printf("%d", Bits_test(&s1, i));
puts("");
}
diff --git a/misc/examples/books.c b/misc/examples/books.c
index 4695941a..098771ae 100644
--- a/misc/examples/books.c
+++ b/misc/examples/books.c
@@ -8,7 +8,7 @@
// would be `HashMap<String, String>` in this example).
int main()
{
- c_AUTO (cmap_str, book_reviews)
+ c_auto (cmap_str, book_reviews)
{
// Review some books.
cmap_str_emplace(&book_reviews,
@@ -41,7 +41,7 @@ int main()
// Look up the values associated with some keys.
const char* to_find[] = {"Pride and Prejudice", "Alice's Adventure in Wonderland"};
- c_FORRANGE (i, c_ARRAYLEN(to_find)) {
+ c_forrange (i, c_ARRAYLEN(to_find)) {
const cmap_str_value* b = cmap_str_get(&book_reviews, to_find[i]);
if (b)
printf("%s: %s\n", cstr_str(&b->first), cstr_str(&b->second));
@@ -53,7 +53,7 @@ int main()
printf("Review for Jane: %s\n", cstr_str(cmap_str_at(&book_reviews, "Pride and Prejudice")));
// Iterate over everything.
- c_FORPAIR (book, review, cmap_str, book_reviews) {
+ c_forpair (book, review, cmap_str, book_reviews) {
printf("%s: \"%s\"\n", cstr_str(_.book), cstr_str(_.review));
}
}
diff --git a/misc/examples/box.c b/misc/examples/box.c
index 3a7a8139..da13501f 100644
--- a/misc/examples/box.c
+++ b/misc/examples/box.c
@@ -37,8 +37,8 @@ void Person_drop(Person* p) {
int main()
{
- c_AUTO (Persons, vec)
- c_AUTO (PBox, p, q)
+ c_auto (Persons, vec)
+ c_auto (PBox, p, q)
{
p = PBox_from(Person_make("Laura", "Palmer"));
q = PBox_clone(p);
@@ -54,12 +54,12 @@ int main()
Persons_push(&vec, PBox_clone(p));
Persons_push(&vec, PBox_clone(q));
- c_FOREACH (i, Persons, vec)
+ c_foreach (i, Persons, vec)
printf("%s %s\n", cstr_str(&i.ref->get->name), cstr_str(&i.ref->get->last));
puts("");
// Look-up Audrey! Create a temporary Person for lookup.
- c_WITH (Person a = Person_make("Audrey", "Home"), Person_drop(&a)) {
+ c_with (Person a = Person_make("Audrey", "Home"), Person_drop(&a)) {
const PBox *v = Persons_get(&vec, a); // lookup
if (v) printf("found: %s %s\n", cstr_str(&v->get->name), cstr_str(&v->get->last));
}
diff --git a/misc/examples/box2.c b/misc/examples/box2.c
index 6281f800..b9628eeb 100644
--- a/misc/examples/box2.c
+++ b/misc/examples/box2.c
@@ -51,9 +51,9 @@ int main(void) {
};
// Declare auto-deleted box objects
- c_AUTO (cbox_Rectangle, boxed_rectangle)
- c_AUTO (cbox_Point, boxed_point)
- c_AUTO (cbox_BoxPoint, box_in_a_box, boxbox2)
+ c_auto (cbox_Rectangle, boxed_rectangle)
+ c_auto (cbox_Point, boxed_point)
+ c_auto (cbox_BoxPoint, box_in_a_box, boxbox2)
{
// Heap allocated rectangle
boxed_rectangle = cbox_Rectangle_make((Rectangle){
diff --git a/misc/examples/city.c b/misc/examples/city.c
index e24c90de..67471cfb 100644
--- a/misc/examples/city.c
+++ b/misc/examples/city.c
@@ -50,42 +50,43 @@ void City_drop(City* c) {
int main(void)
{
- c_AUTO (Cities, cities, copy)
- c_AUTO (CityMap, map)
+ c_auto (Cities, cities, copy)
+ c_auto (CityMap, map)
{
- c_FORLIST (i, City, {
- {cstr_lit("New York"), cstr_lit("US"), 4.3f, 23.2f, 9000000},
- {cstr_lit("Paris"), cstr_lit("France"), 4.3f, 23.2f, 9000000},
- {cstr_lit("Berlin"), cstr_lit("Germany"), 4.3f, 23.2f, 9000000},
- {cstr_lit("London"), cstr_lit("UK"), 4.3f, 23.2f, 9000000},
- }) Cities_emplace(&cities, *i.ref); // NB. creates smart pointers!
+ // Create a cvec with smart pointers to City objects!
+ cities = c_make(Cities, {
+ {cstr_lit("New York"), cstr_lit("US"), 40.71427f, -74.00597f, 8804190},
+ {cstr_lit("Paris"), cstr_lit("France"), 48.85341f, 2.3488f, 2138551},
+ {cstr_lit("Berlin"), cstr_lit("Germany"), 52.52437f, 13.41053f, 3426354},
+ {cstr_lit("London"), cstr_lit("UK"), 51.50853f, -0.12574f, 8961989},
+ });
Cities_sort(&cities);
printf("Vec:\n");
- c_FOREACH (c, Cities, cities)
- printf("city:%s, %d, use:%ld\n", cstr_str(&c.ref->get->name),
+ c_foreach (c, Cities, cities)
+ printf("city: %8s, %8d, use: %ld\n", cstr_str(&c.ref->get->name),
c.ref->get->population,
CityArc_use_count(c.ref));
puts("");
- copy = Cities_clone(cities); // share each element!
+ copy = Cities_clone(cities); // share each city!
int k = 0, id[] = {8, 4, 3, 9, 2, 5};
- c_FOREACH (i, Cities, cities)
+ c_foreach (i, Cities, cities)
CityMap_insert(&map, id[k++], CityArc_clone(*i.ref));
Cities_pop(&cities);
Cities_pop(&cities);
printf("Vec:\n");
- c_FOREACH (c, Cities, cities)
- printf("city:%s, %d, use:%ld\n", cstr_str(&c.ref->get->name),
- c.ref->get->population,
- CityArc_use_count(c.ref));
+ c_foreach (c, Cities, cities)
+ printf("city: %8s, %8d, use: %ld\n", cstr_str(&c.ref->get->name),
+ c.ref->get->population,
+ CityArc_use_count(c.ref));
printf("\nMap:\n");
- c_FORPAIR (id, city, CityMap, map)
- printf("id:%d, city:%s, %d, use:%ld\n", *_.id, cstr_str(&_.city->get->name),
- _.city->get->population, CityArc_use_count(_.city));
+ c_forpair (id, city, CityMap, map)
+ printf("city: %8s, %8d, use: %ld, id:%d\n", cstr_str(&_.city->get->name),
+ _.city->get->population, CityArc_use_count(_.city), *_.id);
puts("");
}
}
diff --git a/misc/examples/complex.c b/misc/examples/complex.c
index 5c212554..e73d7aa1 100644
--- a/misc/examples/complex.c
+++ b/misc/examples/complex.c
@@ -31,7 +31,7 @@
int main()
{
- c_AUTO (MapMap, mmap)
+ c_auto (MapMap, mmap)
{
FloatStack stack = FloatStack_with_size(10, 0);
diff --git a/misc/examples/convert.c b/misc/examples/convert.c
index f2324268..160812b7 100644
--- a/misc/examples/convert.c
+++ b/misc/examples/convert.c
@@ -13,38 +13,38 @@
int main()
{
- c_AUTO (cmap_str, map, mclone)
- c_AUTO (cvec_str, keys, values)
- c_AUTO (clist_str, list)
+ c_auto (cmap_str, map, mclone)
+ c_auto (cvec_str, keys, values)
+ c_auto (clist_str, list)
{
- c_FORLIST (i, cmap_str_raw, {
+ map = c_make(cmap_str, {
{"green", "#00ff00"},
{"blue", "#0000ff"},
{"yellow", "#ffff00"},
- }) cmap_str_emplace(&map, c_PAIR(i.ref));
+ });
puts("MAP:");
- c_FOREACH (i, cmap_str, map)
+ c_foreach (i, cmap_str, map)
printf(" %s: %s\n", cstr_str(&i.ref->first), cstr_str(&i.ref->second));
puts("\nCLONE MAP:");
mclone = cmap_str_clone(map);
- c_FOREACH (i, cmap_str, mclone)
+ c_foreach (i, cmap_str, mclone)
printf(" %s: %s\n", cstr_str(&i.ref->first), cstr_str(&i.ref->second));
puts("\nCOPY MAP TO VECS:");
- c_FOREACH (i, cmap_str, mclone) {
+ c_foreach (i, cmap_str, mclone) {
cvec_str_emplace_back(&keys, cstr_str(&i.ref->first));
cvec_str_emplace_back(&values, cstr_str(&i.ref->second));
}
- c_FORRANGE (i, cvec_str_size(&keys))
+ c_forrange (i, cvec_str_size(&keys))
printf(" %s: %s\n", cstr_str(keys.data + i), cstr_str(values.data + i));
puts("\nCOPY VEC TO LIST:");
- c_FOREACH (i, cvec_str, keys)
+ c_foreach (i, cvec_str, keys)
clist_str_emplace_back(&list, cstr_str(i.ref));
- c_FOREACH (i, clist_str, list)
+ c_foreach (i, clist_str, list)
printf(" %s\n", cstr_str(i.ref));
}
}
diff --git a/misc/examples/csmap_erase.c b/misc/examples/csmap_erase.c
index a41a1ad1..a3bd250b 100644
--- a/misc/examples/csmap_erase.c
+++ b/misc/examples/csmap_erase.c
@@ -10,14 +10,14 @@
void printmap(mymap m)
{
- c_FOREACH (elem, mymap, m)
+ c_foreach (elem, mymap, m)
printf(" [%d, %s]", elem.ref->first, cstr_str(&elem.ref->second));
printf("\nsize() == %" c_ZI "\n\n", mymap_size(&m));
}
int main()
{
- c_AUTO (mymap, m1)
+ c_auto (mymap, m1)
{
// Fill in some data to test with, one at a time
mymap_insert(&m1, 1, cstr_lit("A"));
@@ -34,16 +34,16 @@ int main()
printmap(m1);
}
- c_AUTO (mymap, m2)
+ c_auto (mymap, m2)
{
// Fill in some data to test with, one at a time
- c_FORLIST (i, mymap_raw, {
+ m2 = c_make(mymap, {
{10, "Bob"},
{11, "Rob"},
{12, "Robert"},
{13, "Bert"},
{14, "Bobby"},
- }) mymap_emplace(&m2, c_PAIR(i.ref));
+ });
puts("Starting data of map m2 is:");
printmap(m2);
@@ -51,7 +51,7 @@ int main()
mymap_iter it2 = mymap_find(&m2, mymap_back(&m2)->first);
puts("to remove:");
- c_FOREACH (i, mymap, it1, it2)
+ c_foreach (i, mymap, it1, it2)
printf(" [%d, %s]", i.ref->first, cstr_str(&i.ref->second));
puts("");
// The 2nd member function removes elements
@@ -61,7 +61,7 @@ int main()
printmap(m2);
}
- c_AUTO (mymap, m3)
+ c_auto (mymap, m3)
{
// Fill in some data to test with, one at a time, using emplace
mymap_emplace(&m3, 1, "red");
diff --git a/misc/examples/csmap_find.c b/misc/examples/csmap_find.c
index 201c94e9..fe5558e2 100644
--- a/misc/examples/csmap_find.c
+++ b/misc/examples/csmap_find.c
@@ -20,7 +20,7 @@ void print_elem(csmap_istr_raw p) {
void print_collection_##CX(const CX* t) { \
printf("%" c_ZI " elements: ", CX##_size(t)); \
\
- c_FOREACH (p, CX, *t) { \
+ c_foreach (p, CX, *t) { \
print_elem(CX##_value_toraw(p.ref)); \
} \
puts(""); \
@@ -42,11 +42,10 @@ void findit(csmap_istr c, csmap_istr_key val)
int main()
{
- c_AUTO (csmap_istr, m1)
- c_AUTO (cvec_istr, v)
+ c_auto (csmap_istr, m1)
+ c_auto (cvec_istr, v)
{
- c_FORLIST (i, csmap_istr_raw, {{40, "Zr"}, {45, "Rh"}})
- csmap_istr_emplace(&m1, c_PAIR(i.ref));
+ m1 = c_make(csmap_istr, {{40, "Zr"}, {45, "Rh"}});
puts("The starting map m1 is (key, value):");
print_collection_csmap_istr(&m1);
@@ -62,7 +61,7 @@ int main()
puts("Inserting the following vector data into m1:");
print_collection_cvec_istr(&v);
- c_FOREACH (i, cvec_istr, cvec_istr_begin(&v), cvec_istr_end(&v))
+ c_foreach (i, cvec_istr, cvec_istr_begin(&v), cvec_istr_end(&v))
csmap_istr_emplace(&m1, c_PAIR(i.ref));
puts("The modified map m1 is (key, value):");
diff --git a/misc/examples/csmap_insert.c b/misc/examples/csmap_insert.c
index b1b0a5be..64d71b12 100644
--- a/misc/examples/csmap_insert.c
+++ b/misc/examples/csmap_insert.c
@@ -19,13 +19,13 @@
#include <stc/cvec.h>
void print_ii(csmap_ii map) {
- c_FOREACH (e, csmap_ii, map)
+ c_foreach (e, csmap_ii, map)
printf("(%d, %d) ", e.ref->first, e.ref->second);
puts("");
}
void print_istr(csmap_istr map) {
- c_FOREACH (e, csmap_istr, map)
+ c_foreach (e, csmap_istr, map)
printf("(%d, %s) ", e.ref->first, cstr_str(&e.ref->second));
puts("");
}
@@ -33,7 +33,7 @@ void print_istr(csmap_istr map) {
int main()
{
// insert single values
- c_AUTO (csmap_ii, m1) {
+ c_auto (csmap_ii, m1) {
csmap_ii_insert(&m1, 1, 10);
csmap_ii_insert(&m1, 2, 20);
@@ -60,8 +60,8 @@ int main()
}
// The templatized version inserting a jumbled range
- c_AUTO (csmap_ii, m2)
- c_AUTO (cvec_ii, v) {
+ c_auto (csmap_ii, m2)
+ c_auto (cvec_ii, v) {
typedef cvec_ii_value ipair;
cvec_ii_push(&v, (ipair){43, 294});
cvec_ii_push(&v, (ipair){41, 262});
@@ -70,21 +70,21 @@ int main()
cvec_ii_push(&v, (ipair){44, 311});
puts("Inserting the following vector data into m2:");
- c_FOREACH (e, cvec_ii, v)
+ c_foreach (e, cvec_ii, v)
printf("(%d, %d) ", e.ref->first, e.ref->second);
puts("");
- c_FOREACH (e, cvec_ii, v)
+ c_foreach (e, cvec_ii, v)
csmap_ii_insert_or_assign(&m2, e.ref->first, e.ref->second);
puts("The modified key and mapped values of m2 are:");
- c_FOREACH (e, csmap_ii, m2)
+ c_foreach (e, csmap_ii, m2)
printf("(%d, %d) ", e.ref->first, e.ref->second);
puts("\n");
}
// The templatized versions move-constructing elements
- c_AUTO (csmap_istr, m3) {
+ c_auto (csmap_istr, m3) {
csmap_istr_value ip1 = {475, cstr_lit("blue")}, ip2 = {510, cstr_lit("green")};
// single element
@@ -99,12 +99,9 @@ int main()
puts("");
}
- c_AUTO (csmap_ii, m4) {
+ c_auto (csmap_ii, m4) {
// Insert the elements from an initializer_list
- c_FORLIST (i, csmap_ii_raw, {{ 4, 44 }, { 2, 22 }, { 3, 33 },
- { 1, 11 }, { 5, 55 }})
- csmap_ii_insert(&m4, c_PAIR(i.ref));
-
+ m4 = c_make(csmap_ii, {{4, 44}, {2, 22}, {3, 33}, {1, 11}, {5, 55}});
puts("After initializer_list insertion, m4 contains:");
print_ii(m4);
puts("");
diff --git a/misc/examples/csset_erase.c b/misc/examples/csset_erase.c
index c281c626..e8f2fec5 100644
--- a/misc/examples/csset_erase.c
+++ b/misc/examples/csset_erase.c
@@ -5,12 +5,11 @@
int main()
{
- c_AUTO (csset_int, set)
+ c_auto (csset_int, set)
{
- c_FORLIST (i, int, {30, 20, 80, 40, 60, 90, 10, 70, 50})
- csset_int_insert(&set, *i.ref);
+ set = c_make(csset_int, {30, 20, 80, 40, 60, 90, 10, 70, 50});
- c_FOREACH (k, csset_int, set)
+ c_foreach (k, csset_int, set)
printf(" %d", *k.ref);
puts("");
@@ -19,7 +18,7 @@ int main()
printf("Show values >= %d:\n", val);
it = csset_int_lower_bound(&set, val);
- c_FOREACH (k, csset_int, it, csset_int_end(&set))
+ c_foreach (k, csset_int, it, csset_int_end(&set))
printf(" %d", *k.ref);
puts("");
@@ -27,7 +26,7 @@ int main()
while (it.ref != csset_int_end(&set).ref)
it = csset_int_erase_at(&set, it);
- c_FOREACH (k, csset_int, set)
+ c_foreach (k, csset_int, set)
printf(" %d", *k.ref);
puts("");
@@ -36,7 +35,7 @@ int main()
it = csset_int_lower_bound(&set, val);
csset_int_erase_range(&set, csset_int_begin(&set), it);
- c_FOREACH (k, csset_int, set)
+ c_foreach (k, csset_int, set)
printf(" %d", *k.ref);
puts("");
}
diff --git a/misc/examples/cstr_match.c b/misc/examples/cstr_match.c
index 828ef424..4d11edbb 100644
--- a/misc/examples/cstr_match.c
+++ b/misc/examples/cstr_match.c
@@ -4,7 +4,7 @@
int main()
{
- c_WITH (cstr ss = cstr_lit("The quick brown fox jumps over the lazy dog.JPG"), cstr_drop(&ss)) {
+ c_with (cstr ss = cstr_lit("The quick brown fox jumps over the lazy dog.JPG"), cstr_drop(&ss)) {
intptr_t pos = cstr_find_at(&ss, 0, "brown");
printf("%" c_ZI " [%s]\n", pos, pos == c_NPOS ? "<NULL>" : cstr_str(&ss) + pos);
printf("equals: %d\n", cstr_equals(&ss, "The quick brown fox jumps over the lazy dog.JPG"));
diff --git a/misc/examples/demos.c b/misc/examples/demos.c
index 7070d860..d5336cbf 100644
--- a/misc/examples/demos.c
+++ b/misc/examples/demos.c
@@ -3,7 +3,7 @@
void stringdemo1()
{
printf("\nSTRINGDEMO1\n");
- c_WITH (cstr cs = cstr_lit("one-nine-three-seven-five"), cstr_drop(&cs))
+ c_with (cstr cs = cstr_lit("one-nine-three-seven-five"), cstr_drop(&cs))
{
printf("%s.\n", cstr_str(&cs));
@@ -35,7 +35,7 @@ void stringdemo1()
void vectordemo1()
{
printf("\nVECTORDEMO1\n");
- c_WITH (cvec_ix bignums = cvec_ix_with_capacity(100), cvec_ix_drop(&bignums))
+ c_with (cvec_ix bignums = cvec_ix_with_capacity(100), cvec_ix_drop(&bignums))
{
cvec_ix_reserve(&bignums, 100);
for (int i = 10; i <= 100; i += 10)
@@ -59,7 +59,7 @@ void vectordemo1()
void vectordemo2()
{
printf("\nVECTORDEMO2\n");
- c_AUTO (cvec_str, names) {
+ c_auto (cvec_str, names) {
cvec_str_emplace_back(&names, "Mary");
cvec_str_emplace_back(&names, "Joe");
cvec_str_emplace_back(&names, "Chris");
@@ -67,7 +67,7 @@ void vectordemo2()
printf("names[1]: %s\n", cstr_str(&names.data[1]));
cvec_str_sort(&names); // Sort the array
- c_FOREACH (i, cvec_str, names)
+ c_foreach (i, cvec_str, names)
printf("sorted: %s\n", cstr_str(i.ref));
}
}
@@ -80,7 +80,7 @@ void vectordemo2()
void listdemo1()
{
printf("\nLISTDEMO1\n");
- c_AUTO (clist_ix, nums, nums2)
+ c_auto (clist_ix, nums, nums2)
{
for (int i = 0; i < 10; ++i)
clist_ix_push_back(&nums, i);
@@ -89,7 +89,7 @@ void listdemo1()
/* splice nums2 to front of nums */
clist_ix_splice(&nums, clist_ix_begin(&nums), &nums2);
- c_FOREACH (i, clist_ix, nums)
+ c_foreach (i, clist_ix, nums)
printf("spliced: %d\n", *i.ref);
puts("");
@@ -101,7 +101,7 @@ void listdemo1()
clist_ix_push_back(&nums, -99);
clist_ix_sort(&nums);
- c_FOREACH (i, clist_ix, nums)
+ c_foreach (i, clist_ix, nums)
printf("sorted: %d\n", *i.ref);
}
}
@@ -117,7 +117,7 @@ void setdemo1()
cset_i_insert(&nums, 8);
cset_i_insert(&nums, 11);
- c_FOREACH (i, cset_i, nums)
+ c_foreach (i, cset_i, nums)
printf("set: %d\n", *i.ref);
cset_i_drop(&nums);
}
@@ -145,7 +145,7 @@ void mapdemo1()
void mapdemo2()
{
printf("\nMAPDEMO2\n");
- c_AUTO (cmap_si, nums)
+ c_auto (cmap_si, nums)
{
cmap_si_emplace_or_assign(&nums, "Hello", 64);
cmap_si_emplace_or_assign(&nums, "Groovy", 121);
@@ -156,7 +156,7 @@ void mapdemo2()
printf("long: %s: %d\n", cstr_str(&i.ref->first), i.ref->second);
// or rather use the short form:
- c_FOREACH (i, cmap_si, nums)
+ c_foreach (i, cmap_si, nums)
printf("short: %s: %d\n", cstr_str(&i.ref->first), i.ref->second);
}
}
@@ -173,14 +173,14 @@ void mapdemo3()
cmap_str_emplace(&table, "Make", "my");
cmap_str_emplace(&table, "Sunny", "day");
cmap_str_iter it = cmap_str_find(&table, "Make");
- c_FOREACH (i, cmap_str, table)
+ c_foreach (i, cmap_str, table)
printf("entry: %s: %s\n", cstr_str(&i.ref->first), cstr_str(&i.ref->second));
printf("size %" c_ZI ": remove: Make: %s\n", cmap_str_size(&table), cstr_str(&it.ref->second));
//cmap_str_erase(&table, "Make");
cmap_str_erase_at(&table, it);
printf("size %" c_ZI "\n", cmap_str_size(&table));
- c_FOREACH (i, cmap_str, table)
+ c_foreach (i, cmap_str, table)
printf("entry: %s: %s\n", cstr_str(&i.ref->first), cstr_str(&i.ref->second));
cmap_str_drop(&table); // frees key and value cstrs, and hash table.
}
diff --git a/misc/examples/forfilter.c b/misc/examples/forfilter.c
index d7e1bb1e..b0be4e69 100644
--- a/misc/examples/forfilter.c
+++ b/misc/examples/forfilter.c
@@ -21,18 +21,18 @@
void demo1(void)
{
- c_AUTO (IVec, vec) {
- c_FORLIST (i, int, {0, 1, 2, 3, 4, 5, 80, 6, 7, 80, 8, 9, 80,
+ c_auto (IVec, vec) {
+ c_forlist (i, int, {0, 1, 2, 3, 4, 5, 80, 6, 7, 80, 8, 9, 80,
10, 11, 12, 13, 14, 15, 80, 16, 17})
IVec_push(&vec, *i.ref);
puts("demo1:");
- c_FORFILTER (i, IVec, vec, flt_skipValue(i, 80))
+ c_forfilter (i, IVec, vec, flt_skipValue(i, 80))
printf(" %d", *i.ref);
puts("");
int res, sum = 0;
- c_FORFILTER (i, IVec, vec
+ c_forfilter (i, IVec, vec
, c_flt_skipwhile(i, *i.ref != 80)
&& c_flt_skip(i, 1)
&& c_flt_skipwhile(i, *i.ref != 80)
@@ -62,15 +62,15 @@ fn main() {
void demo2(void)
{
- c_AUTO (IVec, vector) {
+ c_auto (IVec, vector) {
puts("demo2:");
crange R = crange_make(INT64_MAX);
- c_FORFILTER (x, crange, R
+ c_forfilter (x, crange, R
, c_flt_skipwhile(x, *x.ref != 11)
&& *x.ref % 2 != 0
, c_flt_take(x, 5))
IVec_push(&vector, (int)(*x.ref * *x.ref));
- c_FOREACH (x, IVec, vector)
+ c_foreach (x, IVec, vector)
printf(" %d", *x.ref);
puts("");
}
@@ -91,17 +91,17 @@ fn main() {
*/
void demo3(void)
{
- c_AUTO (SVec, words, words_containing_i) {
+ c_auto (SVec, words, words_containing_i) {
const char* sentence = "This is a sentence in C99.";
- c_FORTOKEN (w, sentence, " ")
+ c_fortoken (w, sentence, " ")
SVec_push(&words, *w.ref);
- c_FORFILTER (w, SVec, words,
+ c_forfilter (w, SVec, words,
csview_contains(*w.ref, "i"))
SVec_push(&words_containing_i, *w.ref);
puts("demo3:");
- c_FOREACH (w, SVec, words_containing_i)
+ c_foreach (w, SVec, words_containing_i)
printf(" %.*s", c_SVARG(*w.ref));
puts("");
}
@@ -110,8 +110,8 @@ void demo3(void)
void demo4(void)
{
csview s = c_SV("ab123cReAghNGnΩoEp"); // Ω = multi-byte
- c_AUTO (cstr, out) {
- c_FORFILTER (i, csview, s, utf8_isupper(utf8_peek(i.ref))) {
+ c_auto (cstr, out) {
+ c_forfilter (i, csview, s, utf8_isupper(utf8_peek(i.ref))) {
char chr[4];
utf8_encode(chr, utf8_tolower(utf8_peek(i.ref)));
cstr_push(&out, chr);
@@ -127,7 +127,7 @@ void demo5(void)
#define flt_mid_decade(i) ((*i.ref % 10) != 0)
puts("demo5:");
crange R = crange_make(1963, INT32_MAX);
- c_FORFILTER (i, crange, R
+ c_forfilter (i, crange, R
, c_flt_skip(i,15)
&& c_flt_skipwhile(i, flt_mid_decade(i))
&& c_flt_skip(i,30)
diff --git a/misc/examples/forloops.c b/misc/examples/forloops.c
index cd3c4d9e..66c587c4 100644
--- a/misc/examples/forloops.c
+++ b/misc/examples/forloops.c
@@ -13,61 +13,61 @@
int main()
{
- puts("c_FORRANGE:");
- c_FORRANGE (30) printf(" xx");
+ puts("c_forrange:");
+ c_forrange (30) printf(" xx");
puts("");
- c_FORRANGE (i, 30) printf(" %lld", i);
+ c_forrange (i, 30) printf(" %lld", i);
puts("");
- c_FORRANGE (i, 30, 60) printf(" %lld", i);
+ c_forrange (i, 30, 60) printf(" %lld", i);
puts("");
- c_FORRANGE (i, 30, 90, 2) printf(" %lld", i);
+ c_forrange (i, 30, 90, 2) printf(" %lld", i);
puts("\n\nc_forlist:");
- c_FORLIST (i, int, {12, 23, 453, 65, 676})
+ c_forlist (i, int, {12, 23, 453, 65, 676})
printf(" %d", *i.ref);
puts("");
- c_FORLIST (i, const char*, {"12", "23", "453", "65", "676"})
+ c_forlist (i, const char*, {"12", "23", "453", "65", "676"})
printf(" %s", *i.ref);
puts("");
- c_FORLIST (i, const char*, {"12", "23", "453", "65", "676"})
+ c_forlist (i, const char*, {"12", "23", "453", "65", "676"})
printf(" %s", i.data[i.size - 1 - i.index]);
- c_AUTO (IVec, vec)
- c_AUTO (IMap, map)
+ c_auto (IVec, vec)
+ c_auto (IMap, map)
{
- c_FORLIST (i, int, {12, 23, 453, 65, 113, 215, 676, 34, 67, 20, 27, 66, 189, 45, 280, 199})
+ c_forlist (i, int, {12, 23, 453, 65, 113, 215, 676, 34, 67, 20, 27, 66, 189, 45, 280, 199})
IVec_push(&vec, *i.ref);
- c_FORLIST (i, IMap_value, {{12, 23}, {453, 65}, {676, 123}, {34, 67}})
+ c_forlist (i, IMap_value, {{12, 23}, {453, 65}, {676, 123}, {34, 67}})
IMap_push(&map, *i.ref);
puts("\n\nc_foreach:");
- c_FOREACH (i, IVec, vec)
+ c_foreach (i, IVec, vec)
printf(" %d", *i.ref);
puts("");
- c_FOREACH (i, IMap, map)
+ c_foreach (i, IMap, map)
printf(" (%d %d)", i.ref->first, i.ref->second);
puts("\n\nc_forpair:");
- c_FORPAIR (key, val, IMap, map)
+ c_forpair (key, val, IMap, map)
printf(" (%d %d)", *_.key, *_.val);
puts("\n\nc_forwhile:");
- c_FORWHILE (i, IVec, IVec_begin(&vec), i.index < 3)
+ c_forwhile (i, IVec, IVec_begin(&vec), i.index < 3)
printf(" %d", *i.ref);
#define isOdd(i) (*i.ref & 1)
puts("\n\nc_forfilter:");
- c_FORFILTER (i, IVec, vec
+ c_forfilter (i, IVec, vec
, c_flt_skipwhile(i, *i.ref != 65)
&& c_flt_takewhile(i, *i.ref != 280)
&& c_flt_skipwhile(i, isOdd(i))
diff --git a/misc/examples/functor.c b/misc/examples/functor.c
index f1db3644..6d42c4f8 100644
--- a/misc/examples/functor.c
+++ b/misc/examples/functor.c
@@ -45,23 +45,23 @@ int main()
{
const int data[] = {1,8,5,6,3,4,0,9,7,2}, n = c_ARRAYLEN(data);
printf("data: \t");
- c_FORRANGE (i, n) printf("%d ", data[i]);
+ c_forrange (i, n) printf("%d ", data[i]);
puts("");
IPQueue q1 = {ipque_init(), int_less}; // Max priority queue
IPQueue minq1 = {ipque_init(), int_greater}; // Min priority queue
IPQueue q5 = {ipque_init(), int_lambda}; // Using lambda to compare elements.
- c_DEFER (ipque_drop(&q1.Q), ipque_drop(&minq1.Q), ipque_drop(&q5.Q))
+ c_defer (ipque_drop(&q1.Q), ipque_drop(&minq1.Q), ipque_drop(&q5.Q))
{
- c_FORRANGE (i, n)
+ c_forrange (i, n)
ipque_push(&q1.Q, data[i]);
print_queue("q1", q1);
- c_FORRANGE (i, n)
+ c_forrange (i, n)
ipque_push(&minq1.Q, data[i]);
print_queue("minq1", minq1);
- c_FORRANGE (i, n)
+ c_forrange (i, n)
ipque_push(&q5.Q, data[i]);
print_queue("q5", q5);
}
diff --git a/misc/examples/gauss1.c b/misc/examples/gauss1.c
index 6b06b4e8..40d0981f 100644
--- a/misc/examples/gauss1.c
+++ b/misc/examples/gauss1.c
@@ -29,26 +29,26 @@ int main()
stc64_normalf_t dist = stc64_normalf_new(Mean, StdDev);
// Create and init histogram vec and map with defered destructors:
- c_AUTO (cvec_ii, histvec)
- c_AUTO (cmap_ii, histmap)
+ c_auto (cvec_ii, histvec)
+ c_auto (cmap_ii, histmap)
{
- c_FORRANGE (N) {
+ c_forrange (N) {
int index = (int)round( stc64_normalf(&rng, &dist) );
cmap_ii_insert(&histmap, index, 0).ref->second += 1;
}
// Transfer map to vec and sort it by map keys.
- c_FOREACH (i, cmap_ii, histmap)
+ c_foreach (i, cmap_ii, histmap)
cvec_ii_push(&histvec, (cmap_ii_value){i.ref->first, i.ref->second});
cvec_ii_sort(&histvec);
// Print the gaussian bar chart
- c_FOREACH (i, cvec_ii, histvec) {
+ c_foreach (i, cvec_ii, histvec) {
int n = (int)(i.ref->second * StdDev * Scale * 2.5 / (double)N);
if (n > 0) {
printf("%4d ", i.ref->first);
- c_FORRANGE (n) printf("*");
+ c_forrange (n) printf("*");
puts("");
}
}
diff --git a/misc/examples/gauss2.c b/misc/examples/gauss2.c
index 96ab9d6d..c531e5e3 100644
--- a/misc/examples/gauss2.c
+++ b/misc/examples/gauss2.c
@@ -22,16 +22,16 @@ int main()
stc64_normalf_t dist = stc64_normalf_new(Mean, StdDev);
// Create and init histogram map with defered destruct
- c_AUTO (csmap_int, mhist)
+ c_auto (csmap_int, mhist)
{
- c_FORRANGE (N) {
+ c_forrange (N) {
int index = (int) round( stc64_normalf(&rng, &dist) );
csmap_int_insert(&mhist, index, 0).ref->second += 1;
}
// Print the gaussian bar chart
- c_AUTO (cstr, bar)
- c_FORPAIR (index, count, csmap_int, mhist) {
+ c_auto (cstr, bar)
+ c_forpair (index, count, csmap_int, mhist) {
int n = (int)((float)*_.count * StdDev * Scale * 2.5f / (float)N);
if (n > 0) {
cstr_resize(&bar, n, '*');
diff --git a/misc/examples/hashmap.c b/misc/examples/hashmap.c
index bc4f2566..f59ed824 100644
--- a/misc/examples/hashmap.c
+++ b/misc/examples/hashmap.c
@@ -17,7 +17,7 @@ const char* call(const char* number) {
}
int main(void) {
- c_AUTO (cmap_str, contacts)
+ c_auto (cmap_str, contacts)
{
cmap_str_emplace(&contacts, "Daniel", "798-1364");
cmap_str_emplace(&contacts, "Ashley", "645-7689");
@@ -40,7 +40,7 @@ int main(void) {
cmap_str_erase(&contacts, "Ashley");
puts("");
- c_FORPAIR (contact, number, cmap_str, contacts) {
+ c_forpair (contact, number, cmap_str, contacts) {
printf("Calling %s: %s\n", cstr_str(_.contact), call(cstr_str(_.number)));
}
puts("");
diff --git a/misc/examples/inits.c b/misc/examples/inits.c
index 459a0ec1..3d03ee91 100644
--- a/misc/examples/inits.c
+++ b/misc/examples/inits.c
@@ -36,11 +36,11 @@ int main(void)
{
// CVEC FLOAT / PRIORITY QUEUE
- c_AUTO (cpque_f, floats) {
+ c_auto (cpque_f, floats) {
const float nums[] = {4.0f, 2.0f, 5.0f, 3.0f, 1.0f};
// PRIORITY QUEUE
- c_FORRANGE (i, c_ARRAYLEN(nums))
+ c_forrange (i, c_ARRAYLEN(nums))
cpque_f_push(&floats, nums[i]);
puts("\npop and show high priorites first:");
@@ -54,20 +54,21 @@ int main(void)
// CMAP ID
int year = 2020;
- c_AUTO (cmap_id, idnames) {
+ c_auto (cmap_id, idnames) {
cmap_id_emplace(&idnames, 100, "Hello");
cmap_id_insert(&idnames, 110, cstr_lit("World"));
cmap_id_insert(&idnames, 120, cstr_from_fmt("Howdy, -%d-", year));
- c_FOREACH (i, cmap_id, idnames)
+ c_foreach (i, cmap_id, idnames)
printf("%d: %s\n", i.ref->first, cstr_str(&i.ref->second));
puts("");
}
// CMAP CNT
- c_AUTO (cmap_cnt, countries) {
- c_FORLIST (i, cmap_cnt_raw, {
+ c_auto (cmap_cnt, countries)
+ {
+ countries = c_make(cmap_cnt, {
{"Norway", 100},
{"Denmark", 50},
{"Iceland", 10},
@@ -76,40 +77,37 @@ int main(void)
{"Germany", 10},
{"Spain", 10},
{"France", 10},
- }) cmap_cnt_emplace(&countries, c_PAIR(i.ref));
-
+ });
cmap_cnt_emplace(&countries, "Greenland", 0).ref->second += 20;
cmap_cnt_emplace(&countries, "Sweden", 0).ref->second += 20;
cmap_cnt_emplace(&countries, "Norway", 0).ref->second += 20;
cmap_cnt_emplace(&countries, "Finland", 0).ref->second += 20;
- c_FORPAIR (country, health, cmap_cnt, countries)
+ c_forpair (country, health, cmap_cnt, countries)
printf("%s: %d\n", cstr_str(_.country), *_.health);
puts("");
}
// CVEC PAIR
- c_AUTO (cvec_ip, pairs1) {
- c_FORLIST (i, ipair_t, {{5, 6}, {3, 4}, {1, 2}, {7, 8}})
- cvec_ip_push_back(&pairs1, *i.ref);
+ c_auto (cvec_ip, pairs1) {
+ pairs1 = c_make(cvec_ip, {{5, 6}, {3, 4}, {1, 2}, {7, 8}});
cvec_ip_sort(&pairs1);
- c_FOREACH (i, cvec_ip, pairs1)
+ c_foreach (i, cvec_ip, pairs1)
printf("(%d %d) ", i.ref->x, i.ref->y);
puts("");
}
// CLIST PAIR
- c_AUTO (clist_ip, pairs2) {
- c_FORLIST (i, ipair_t, {{5, 6}, {3, 4}, {1, 2}, {7, 8}})
- clist_ip_push_back(&pairs2, *i.ref);
+ c_auto (clist_ip, pairs2) {
+ pairs2 = c_make(clist_ip, {{5, 6}, {3, 4}, {1, 2}, {7, 8}});
clist_ip_sort(&pairs2);
- c_FOREACH (i, clist_ip, pairs2)
+ c_foreach (i, clist_ip, pairs2)
printf("(%d %d) ", i.ref->x, i.ref->y);
puts("");
}
diff --git a/misc/examples/intrusive.c b/misc/examples/intrusive.c
index 20a37055..ce8a3ada 100644
--- a/misc/examples/intrusive.c
+++ b/misc/examples/intrusive.c
@@ -14,27 +14,27 @@
void printLists(Inner inner, Outer outer) {
printf(" inner:");
- c_FOREACH (i, Inner, inner)
+ c_foreach (i, Inner, inner)
printf(" %d", *i.ref);
printf("\n outer:");
- c_FOREACH (i, Outer, outer)
+ c_foreach (i, Outer, outer)
printf(" %d", i.ref->value);
puts("");
}
int main()
{
- c_AUTO (Outer, outer)
+ c_auto (Outer, outer)
{
Inner inner = Inner_init(); // do not destroy, outer will destroy the shared nodes.
- c_FORLIST (i, int, {6, 9, 3, 1, 7, 4, 5, 2, 8}) {
+ c_forlist (i, int, {6, 9, 3, 1, 7, 4, 5, 2, 8}) {
Inner_node* node = Outer_push_back(&outer, (Inner_node){0});
node->value = *i.ref;
}
- c_FOREACH (i, Outer, outer)
+ c_foreach (i, Outer, outer)
Inner_push_node_back(&inner, i.ref);
printLists(inner, outer);
@@ -46,7 +46,7 @@ int main()
puts("Remove odd numbers from inner list");
- c_FOREACH (i, Inner, inner)
+ c_foreach (i, Inner, inner)
if (*i.ref & 1)
Inner_unlink_node_after(&inner, i.prev);
diff --git a/misc/examples/list.c b/misc/examples/list.c
index ced0be32..1eb58802 100644
--- a/misc/examples/list.c
+++ b/misc/examples/list.c
@@ -10,37 +10,37 @@
int main() {
const int n = 2000000;
- c_AUTO (clist_fx, list)
+ c_auto (clist_fx, list)
{
stc64_t rng = stc64_new(1234);
stc64_uniformf_t dist = stc64_uniformf_new(100.0f, n);
int m = 0;
- c_FORRANGE (n)
+ c_forrange (n)
clist_fx_push_back(&list, stc64_uniformf(&rng, &dist)), ++m;
double sum = 0.0;
printf("sumarize %d:\n", m);
- c_FOREACH (i, clist_fx, list)
+ c_foreach (i, clist_fx, list)
sum += *i.ref;
printf("sum %f\n\n", sum);
- c_FORWHILE (i, clist_fx, clist_fx_begin(&list), i.index < 10)
+ c_forwhile (i, clist_fx, clist_fx_begin(&list), i.index < 10)
printf("%8d: %10f\n", (int)i.index, *i.ref);
puts("sort");
clist_fx_sort(&list); // mergesort O(n*log n)
puts("sorted");
- c_FORWHILE (i, clist_fx, clist_fx_begin(&list), i.index < 10)
+ c_forwhile (i, clist_fx, clist_fx_begin(&list), i.index < 10)
printf("%8d: %10f\n", (int)i.index, *i.ref);
puts("");
clist_fx_clear(&list);
- c_FORLIST (i, int, {10, 20, 30, 40, 30, 50})
+ c_forlist (i, int, {10, 20, 30, 40, 30, 50})
clist_fx_push_back(&list, *i.ref);
const double* v = clist_fx_get(&list, 30);
printf("found: %f\n", *v);
- c_FOREACH (i, clist_fx, list) printf(" %g", *i.ref);
+ c_foreach (i, clist_fx, list) printf(" %g", *i.ref);
puts("");
clist_fx_remove(&list, 30);
@@ -49,10 +49,10 @@ int main() {
clist_fx_push_front(&list, 1964);
clist_fx_iter it = clist_fx_begin(&list);
printf("Full: ");
- c_FOREACH (i, clist_fx, list)
+ c_foreach (i, clist_fx, list)
printf(" %g", *i.ref);
printf("\nSubs: ");
- c_FOREACH (i, clist_fx, clist_fx_advance(it, 4), clist_fx_end(&list))
+ c_foreach (i, clist_fx, clist_fx_advance(it, 4), clist_fx_end(&list))
printf(" %g", *i.ref);
puts("");
}
diff --git a/misc/examples/list_erase.c b/misc/examples/list_erase.c
index 18ad0d16..47f56625 100644
--- a/misc/examples/list_erase.c
+++ b/misc/examples/list_erase.c
@@ -7,12 +7,9 @@
int main ()
{
- c_WITH (IList L = IList_init(), IList_drop(&L))
+ c_with (IList L = c_make(IList, {10, 20, 30, 40, 50}), IList_drop(&L))
{
- c_FORLIST (i, int, {10, 20, 30, 40, 50})
- IList_push(&L, *i.ref);
-
- c_FOREACH (x, IList, L)
+ c_foreach (x, IList, L)
printf("%d ", *x.ref);
puts("");
// 10 20 30 40 50
@@ -25,7 +22,7 @@ int main ()
it = IList_erase_range(&L, it, end); // 10 30
// ^
printf("list contains:");
- c_FOREACH (x, IList, L)
+ c_foreach (x, IList, L)
printf(" %d", *x.ref);
puts("");
}
diff --git a/misc/examples/list_splice.c b/misc/examples/list_splice.c
index 8a5dae76..f2f4946f 100644
--- a/misc/examples/list_splice.c
+++ b/misc/examples/list_splice.c
@@ -8,7 +8,7 @@
void print_ilist(const char* s, clist_i list)
{
printf("%s", s);
- c_FOREACH (i, clist_i, list) {
+ c_foreach (i, clist_i, list) {
printf(" %d", *i.ref);
}
puts("");
@@ -16,13 +16,10 @@ void print_ilist(const char* s, clist_i list)
int main ()
{
- c_AUTO (clist_i, list1, list2)
+ c_auto (clist_i, list1, list2)
{
- c_FORLIST (i, int, {1, 2, 3, 4, 5})
- clist_i_push_back(&list1, *i.ref);
-
- c_FORLIST (i, int, {10, 20, 30, 40, 50})
- clist_i_push_back(&list2, *i.ref);
+ list1 = c_make(clist_i, {1, 2, 3, 4, 5});
+ list2 = c_make(clist_i, {10, 20, 30, 40, 50});
print_ilist("list1:", list1);
print_ilist("list2:", list2);
diff --git a/misc/examples/lower_bound.c b/misc/examples/lower_bound.c
index 8d048e7c..f492ccaa 100644
--- a/misc/examples/lower_bound.c
+++ b/misc/examples/lower_bound.c
@@ -9,12 +9,10 @@
int main()
{
// TEST SORTED VECTOR
- c_AUTO (cvec_int, vec)
+ c_auto (cvec_int, vec)
{
int key, *res;
-
- c_FORLIST (i, int, {40, 600, 1, 7000, 2, 500, 30})
- cvec_int_push(&vec, *i.ref);
+ vec = c_make(cvec_int, {40, 600, 1, 7000, 2, 500, 30});
cvec_int_sort(&vec);
@@ -33,19 +31,17 @@ int main()
if (it2.ref)
printf("Sorted Vec %d: bin. search: %d\n", key, *it2.ref); // 600
- c_FOREACH (i, cvec_int, it1, it2)
+ c_foreach (i, cvec_int, it1, it2)
printf(" %d\n", *i.ref);
puts("");
}
// TEST SORTED SET
- c_AUTO (csset_int, set)
+ c_auto (csset_int, set)
{
int key, *res;
-
- c_FORLIST (i, int, {40, 600, 1, 7000, 2, 500, 30})
- csset_int_push(&set, *i.ref);
+ set = c_make(csset_int, {40, 600, 1, 7000, 2, 500, 30});
key = 100;
res = csset_int_lower_bound(&set, key).ref;
@@ -62,7 +58,7 @@ int main()
if (it2.ref)
printf("Sorted Set %d: find : %d\n", key, *it2.ref); // 600
- c_FOREACH (i, csset_int, it1, it2)
+ c_foreach (i, csset_int, it1, it2)
printf(" %d\n", *i.ref);
}
}
diff --git a/misc/examples/mapmap.c b/misc/examples/mapmap.c
index d5fe9c81..cad5e462 100644
--- a/misc/examples/mapmap.c
+++ b/misc/examples/mapmap.c
@@ -36,7 +36,7 @@ void add(Departments* deps, const char* name, const char* email, const char* dep
int contains(Departments* map, const char* name)
{
int count = 0;
- c_FOREACH (i, Departments, *map)
+ c_foreach (i, Departments, *map)
if (People_contains(&i.ref->second, name))
++count;
return count;
@@ -44,7 +44,7 @@ int contains(Departments* map, const char* name)
int main(void)
{
- c_AUTO (Departments, map)
+ c_auto (Departments, map)
{
add(&map, "Anna Kendro", "[email protected]", "Support");
add(&map, "Terry Dane", "[email protected]", "Development");
@@ -60,8 +60,8 @@ int main(void)
add(&map, "Dennis Kay", "[email protected]", "Marketing");
add(&map, "Anne Dickens", "[email protected]", "Development");
- c_FOREACH (i, Departments, map)
- c_FORPAIR (name, email, People, i.ref->second)
+ c_foreach (i, Departments, map)
+ c_forpair (name, email, People, i.ref->second)
printf("%s: %s - %s\n", cstr_str(&i.ref->first), cstr_str(_.name), cstr_str(_.email));
puts("");
diff --git a/misc/examples/mmap.c b/misc/examples/mmap.c
index ada30b98..3934cf26 100644
--- a/misc/examples/mmap.c
+++ b/misc/examples/mmap.c
@@ -18,8 +18,8 @@
void print(const char* lbl, const Multimap mmap)
{
printf("%s ", lbl);
- c_FOREACH (e, Multimap, mmap) {
- c_FOREACH (s, clist_str, e.ref->second)
+ c_foreach (e, Multimap, mmap) {
+ c_foreach (s, clist_str, e.ref->second)
printf("{%d,%s} ", e.ref->first, cstr_str(s.ref));
}
puts("");
@@ -33,12 +33,12 @@ void insert(Multimap* mmap, int key, const char* str)
int main()
{
- c_AUTO (Multimap, mmap)
+ c_auto (Multimap, mmap)
{
typedef struct {int a; const char* b;} pair;
// list-initialize
- c_FORLIST (i, pair, {{2, "foo"}, {2, "bar"}, {3, "baz"}, {1, "abc"}, {5, "def"}})
+ c_forlist (i, pair, {{2, "foo"}, {2, "bar"}, {3, "baz"}, {1, "abc"}, {5, "def"}})
insert(&mmap, i.ref->a, i.ref->b);
print("#1", mmap);
@@ -54,7 +54,7 @@ int main()
print("#4", mmap);
// insert using initialization_list
- c_FORLIST (i, pair, {{5, "one"}, {5, "two"}})
+ c_forlist (i, pair, {{5, "one"}, {5, "two"}})
insert(&mmap, i.ref->a, i.ref->b);
print("#5", mmap);
@@ -65,7 +65,7 @@ int main()
Multimap_clear(&mmap);
- c_FORLIST (i, pair, {{1, "ä"}, {2, "ё"}, {2, "ö"}, {3, "ü"}})
+ c_forlist (i, pair, {{1, "ä"}, {2, "ё"}, {2, "ö"}, {3, "ü"}})
insert(&mmap, i.ref->a, i.ref->b);
print("#6", mmap);
}
diff --git a/misc/examples/multidim.c b/misc/examples/multidim.c
index e61959ca..3980e6d8 100644
--- a/misc/examples/multidim.c
+++ b/misc/examples/multidim.c
@@ -8,9 +8,7 @@ using_cspan3(ispan, int);
int main()
{
- cstack_int v = {0};
- c_FORLIST (i, int, {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24})
- cstack_int_push(&v, *i.ref);
+ cstack_int v = c_make(cstack_int, {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24});
// View data as contiguous memory representing 24 ints
ispan ms1 = cspan_from(&v);
@@ -44,7 +42,7 @@ int main()
}
puts("Iterate ss3 flat:");
- c_FOREACH (i, ispan3, ss3)
+ c_foreach (i, ispan3, ss3)
printf(" %d", *i.ref);
puts("");
@@ -62,7 +60,7 @@ int main()
puts("iterate subspan ms3[1]:");
ispan2 sub = cspan_submd3(&ms3, 1);
- c_FOREACH (i, ispan2, sub)
+ c_foreach (i, ispan2, sub)
printf(" %d", *i.ref);
puts("");
diff --git a/misc/examples/multimap.c b/misc/examples/multimap.c
index ba0bf71b..1d5d259d 100644
--- a/misc/examples/multimap.c
+++ b/misc/examples/multimap.c
@@ -69,7 +69,7 @@ void OlympicLoc_drop(OlympicLoc* self) {
int main()
{
// Define the multimap with destructor defered to when block is completed.
- c_AUTO (csmap_OL, multimap)
+ c_auto (csmap_OL, multimap)
{
const clist_OL empty = clist_OL_init();
@@ -85,14 +85,14 @@ int main()
clist_OL_push_back(list, loc);
}
// Sort locations by year for each country.
- c_FOREACH (country, csmap_OL, multimap)
+ c_foreach (country, csmap_OL, multimap)
clist_OL_sort(&country.ref->second);
// Print the multimap:
- c_FOREACH (country, csmap_OL, multimap)
+ c_foreach (country, csmap_OL, multimap)
{
// Loop the locations for a country sorted by year
- c_FOREACH (loc, clist_OL, country.ref->second)
+ c_foreach (loc, clist_OL, country.ref->second)
printf("%s: %d, %s, %s\n", cstr_str(&country.ref->first),
loc.ref->year,
cstr_str(&loc.ref->city),
diff --git a/misc/examples/music_arc.c b/misc/examples/music_arc.c
index fad7ddcf..2a2d24c5 100644
--- a/misc/examples/music_arc.c
+++ b/misc/examples/music_arc.c
@@ -32,16 +32,16 @@ void Song_drop(Song* s) {
void example3()
{
- c_AUTO (SongVec, vec1, vec2)
+ c_auto (SongVec, vec1, vec2)
{
- c_FORLIST (i, Song, {
+ vec1 = c_make(SongVec, {
Song_make("Bob Dylan", "The Times They Are A Changing"),
Song_make("Aretha Franklin", "Bridge Over Troubled Water"),
Song_make("Thalia", "Entre El Mar y Una Estrella")
- }) SongVec_emplace(&vec1, *i.ref);
+ });
// Share all entries in vec with vec2, except Bob Dylan.
- c_FOREACH (s, SongVec, vec1)
+ c_foreach (s, SongVec, vec1)
if (!cstr_equals(&s.ref->get->artist, "Bob Dylan"))
SongVec_push(&vec2, SongArc_clone(*s.ref));
@@ -52,9 +52,9 @@ void example3()
// SongVec_push(&vec2, SongArc_from(Song_make("Rihanna", "Stay")));
// We now have two vectors with some shared, some unique entries.
- c_FORLIST (i, SongVec, {vec1, vec2}) {
+ c_forlist (i, SongVec, {vec1, vec2}) {
puts("VEC:");
- c_FOREACH (s, SongVec, *i.ref)
+ c_foreach (s, SongVec, *i.ref)
printf(" %s - %s, REFS: %ld\n", cstr_str(&s.ref->get->artist),
cstr_str(&s.ref->get->title),
*s.ref->use_count);
diff --git a/misc/examples/new_deq.c b/misc/examples/new_deq.c
index df9142e7..39149140 100644
--- a/misc/examples/new_deq.c
+++ b/misc/examples/new_deq.c
@@ -36,25 +36,25 @@ int point_cmp(const Point* a, const Point* b) {
int main()
{
- c_AUTO (cdeq_i32, vec)
+ c_auto (cdeq_i32, vec)
{
cdeq_i32_push_back(&vec, 123);
}
- c_AUTO (cdeq_float, fvec)
+ c_auto (cdeq_float, fvec)
{
cdeq_float_push_back(&fvec, 123.3f);
}
- c_AUTO (cdeq_pnt, pvec)
+ c_auto (cdeq_pnt, pvec)
{
cdeq_pnt_push_back(&pvec, (Point){42, 14});
cdeq_pnt_push_back(&pvec, (Point){32, 94});
cdeq_pnt_push_front(&pvec, (Point){62, 81});
cdeq_pnt_sort(&pvec);
- c_FOREACH (i, cdeq_pnt, pvec)
+ c_foreach (i, cdeq_pnt, pvec)
printf(" (%d %d)", i.ref->x, i.ref->y);
puts("");
}
- c_AUTO (cdeq_str, svec)
+ c_auto (cdeq_str, svec)
{
cdeq_str_emplace_back(&svec, "Hello, friend");
}
diff --git a/misc/examples/new_list.c b/misc/examples/new_list.c
index c5d90ad1..6dbe80b4 100644
--- a/misc/examples/new_list.c
+++ b/misc/examples/new_list.c
@@ -35,27 +35,27 @@ int point_cmp(const Point* a, const Point* b) {
int main()
{
- c_AUTO (clist_i32, lst)
+ c_auto (clist_i32, lst)
clist_i32_push_back(&lst, 123);
- c_AUTO (clist_pnt, plst) {
- c_FORLIST (i, Point, {{42, 14}, {32, 94}, {62, 81}})
+ c_auto (clist_pnt, plst) {
+ c_forlist (i, Point, {{42, 14}, {32, 94}, {62, 81}})
clist_pnt_push_back(&plst, *i.ref);
clist_pnt_sort(&plst);
- c_FOREACH (i, clist_pnt, plst)
+ c_foreach (i, clist_pnt, plst)
printf(" (%d %d)", i.ref->x, i.ref->y);
puts("");
}
- c_AUTO (clist_float, flst) {
- c_FORLIST (i, float, {123.3f, 321.2f, -32.2f, 78.2f})
+ c_auto (clist_float, flst) {
+ c_forlist (i, float, {123.3f, 321.2f, -32.2f, 78.2f})
clist_float_push_back(&flst, *i.ref);
- c_FOREACH (i, clist_float, flst) printf(" %g", *i.ref);
+ c_foreach (i, clist_float, flst) printf(" %g", *i.ref);
}
- c_AUTO (clist_str, slst)
+ c_auto (clist_str, slst)
clist_str_emplace_back(&slst, "Hello, friend");
}
diff --git a/misc/examples/new_map.c b/misc/examples/new_map.c
index 9cee987d..a4d5289c 100644
--- a/misc/examples/new_map.c
+++ b/misc/examples/new_map.c
@@ -42,10 +42,10 @@ int point_cmp(const Point* a, const Point* b) {
int main()
{
- c_AUTO (cmap_int, map)
- c_AUTO (cmap_pnt, pmap)
- c_AUTO (cmap_str, smap)
- c_AUTO (cset_str, sset)
+ c_auto (cmap_int, map)
+ c_auto (cmap_pnt, pmap)
+ c_auto (cmap_str, smap)
+ c_auto (cset_str, sset)
{
cmap_int_insert(&map, 123, 321);
cmap_int_insert(&map, 456, 654);
@@ -53,7 +53,7 @@ int main()
pmap = c_make(cmap_pnt, {{{42, 14}, 1}, {{32, 94}, 2}, {{62, 81}, 3}});
- c_FOREACH (i, cmap_pnt, pmap)
+ c_foreach (i, cmap_pnt, pmap)
printf(" (%d, %d: %d)", i.ref->first.x, i.ref->first.y, i.ref->second);
puts("");
@@ -68,7 +68,7 @@ int main()
"So long",
});
- c_FOREACH (i, cset_str, sset)
+ c_foreach (i, cset_str, sset)
printf(" %s\n", cstr_str(i.ref));
}
}
diff --git a/misc/examples/new_pque.c b/misc/examples/new_pque.c
index b3d94c2f..1442f376 100644
--- a/misc/examples/new_pque.c
+++ b/misc/examples/new_pque.c
@@ -1,55 +1,25 @@
#include <stdio.h>
-#define i_val int
-#include <stc/cstack.h>
-#define i_val int
-#include <stc/cpque.h>
-
struct Point { int x, y; } typedef Point;
-int Point_cmp(const Point* a, const Point* b) {
- int c = a->x - b->x;
- return c ? c : a->y - b->y;
-}
-
+#define i_type PointQ
#define i_val Point
-#define i_cmp Point_cmp
-#define i_tag pnt
+#define i_less(a, b) a->x < b->x || a->x == b->x && a->y < b->y
#include <stc/cpque.h>
int main()
{
- c_AUTO (cstack_int, istk)
- {
- cstack_int_push(&istk, 123);
- cstack_int_push(&istk, 321);
- // print
- c_FOREACH (i, cstack_int, istk)
- printf(" %d", *i.ref);
- puts("");
- }
- c_AUTO (cpque_pnt, pque)
+ c_auto (PointQ, pque)
{
- cpque_pnt_push(&pque, (Point){23, 80});
- cpque_pnt_push(&pque, (Point){12, 32});
- cpque_pnt_push(&pque, (Point){54, 74});
- cpque_pnt_push(&pque, (Point){12, 62});
+ pque = c_make(PointQ, {{23, 80}, {12, 32}, {54, 74}, {12, 62}});
+
// print
- while (!cpque_pnt_empty(&pque)) {
- const cpque_pnt_value *v = cpque_pnt_top(&pque);
+ for (; !PointQ_empty(&pque); PointQ_pop(&pque))
+ {
+ const Point *v = PointQ_top(&pque);
printf(" (%d,%d)", v->x, v->y);
- cpque_pnt_pop(&pque);
}
puts("");
}
- c_AUTO (cpque_int, ique)
- {
- cpque_int_push(&ique, 123);
- cpque_int_push(&ique, 321);
- // print
- for (int i=0; i<cpque_int_size(&ique); ++i)
- printf(" %d", ique.data[i]);
- puts("");
- }
}
diff --git a/misc/examples/new_queue.c b/misc/examples/new_queue.c
index 5c25a229..7fae90d2 100644
--- a/misc/examples/new_queue.c
+++ b/misc/examples/new_queue.c
@@ -25,16 +25,16 @@ int main() {
stc64_t rng = stc64_new((uint64_t)time(NULL));
stc64_uniform_t dist = stc64_uniform_new(0, n);
- c_AUTO (IQ, Q)
+ c_auto (IQ, Q)
{
// Push 50'000'000 random numbers onto the queue.
- c_FORRANGE (n)
+ c_forrange (n)
IQ_push(&Q, (int)stc64_uniform(&rng, &dist));
// Push or pop on the queue 50 million times
printf("befor: size %" c_ZI ", capacity %" c_ZI "\n", IQ_size(&Q), IQ_capacity(&Q));
- c_FORRANGE (n) {
+ c_forrange (n) {
int r = (int)stc64_uniform(&rng, &dist);
if (r & 3)
IQ_push(&Q, r);
diff --git a/misc/examples/new_smap.c b/misc/examples/new_smap.c
index 8b1df828..0870ee3d 100644
--- a/misc/examples/new_smap.c
+++ b/misc/examples/new_smap.c
@@ -42,34 +42,34 @@ int point_cmp(const Point* a, const Point* b) {
int main()
{
- c_AUTO (csmap_int, imap) {
+ c_auto (csmap_int, imap) {
csmap_int_insert(&imap, 123, 321);
}
- c_AUTO (PMap, pmap) {
- c_FORLIST (i, PMap_value, {
+ c_auto (PMap, pmap) {
+ pmap = c_make(PMap, {
{{42, 14}, 1},
{{32, 94}, 2},
{{62, 81}, 3},
- }) PMap_insert(&pmap, c_PAIR(i.ref));
+ });
- c_FORPAIR (p, i, PMap, pmap)
+ c_forpair (p, i, PMap, pmap)
printf(" (%d,%d: %d)", _.p->x, _.p->y, *_.i);
puts("");
}
- c_AUTO (SMap, smap) {
- c_FORLIST (i, SMap_raw, {
+ c_auto (SMap, smap) {
+ smap = c_make(SMap, {
{"Hello, friend", "this is the mapped value"},
{"The brown fox", "jumped"},
{"This is the time", "for all good things"},
- }) SMap_emplace(&smap, c_PAIR(i.ref));
+ });
- c_FORPAIR (i, j, SMap, smap)
+ c_forpair (i, j, SMap, smap)
printf(" (%s: %s)\n", cstr_str(_.i), cstr_str(_.j));
}
- c_AUTO (SSet, sset) {
+ c_auto (SSet, sset) {
SSet_emplace(&sset, "Hello, friend");
SSet_emplace(&sset, "Goodbye, foe");
printf("Found? %s\n", SSet_contains(&sset, "Hello, friend") ? "true" : "false");
diff --git a/misc/examples/new_sptr.c b/misc/examples/new_sptr.c
index 116827a4..68454970 100644
--- a/misc/examples/new_sptr.c
+++ b/misc/examples/new_sptr.c
@@ -48,7 +48,7 @@ void Person_drop(Person* p) {
int main(void) {
- c_AUTO (PersonArc, p, q, r, s)
+ c_auto (PersonArc, p, q, r, s)
{
puts("Ex1");
p = PersonArc_from(Person_make("John", "Smiths"));
@@ -57,7 +57,7 @@ int main(void) {
s = PersonArc_from(Person_clone(*p.get)); // deep copy
printf("%s %s: refs %ld\n", cstr_str(&p.get->name), cstr_str(&p.get->last), *p.use_count);
}
- c_AUTO (IPStack, vec)
+ c_auto (IPStack, vec)
{
puts("Ex2");
IPStack_push(&vec, IPtr_from(10));
@@ -66,7 +66,7 @@ int main(void) {
IPStack_push(&vec, IPtr_clone(*IPStack_back(&vec)));
IPStack_push(&vec, IPtr_clone(*IPStack_front(&vec)));
- c_FOREACH (i, IPStack, vec)
+ c_foreach (i, IPStack, vec)
printf(" (%d: refs %ld)", *i.ref->get, *i.ref->use_count);
puts("");
}
diff --git a/misc/examples/new_vec.c b/misc/examples/new_vec.c
index f18bf368..84e4c7b2 100644
--- a/misc/examples/new_vec.c
+++ b/misc/examples/new_vec.c
@@ -36,10 +36,10 @@ int point_cmp(const Point* a, const Point* b) {
int main()
{
- c_AUTO (cvec_i32, vec)
- c_AUTO (cvec_float, fvec)
- c_AUTO (cvec_pnt, pvec)
- c_AUTO (cvec_str, svec)
+ c_auto (cvec_i32, vec)
+ c_auto (cvec_float, fvec)
+ c_auto (cvec_pnt, pvec)
+ c_auto (cvec_str, svec)
{
cvec_i32_push(&vec, 123);
cvec_float_push(&fvec, 123.3f);
@@ -49,7 +49,7 @@ int main()
cvec_pnt_push(&pvec, (Point){62, 81});
cvec_pnt_push(&pvec, (Point){32, 91});
cvec_pnt_sort(&pvec);
- c_FOREACH (i, cvec_pnt, pvec)
+ c_foreach (i, cvec_pnt, pvec)
printf(" (%d %d)", i.ref->x, i.ref->y);
puts("");
diff --git a/misc/examples/person_arc.c b/misc/examples/person_arc.c
index 4d9c2a51..a7bf2a6f 100644
--- a/misc/examples/person_arc.c
+++ b/misc/examples/person_arc.c
@@ -39,8 +39,8 @@ void Person_drop(Person* p) {
int main()
{
- c_AUTO (Persons, vec)
- c_AUTO (PSPtr, p, q)
+ c_auto (Persons, vec)
+ c_auto (PSPtr, p, q)
{
p = PSPtr_from(Person_make("Laura", "Palmer"));
@@ -57,15 +57,15 @@ int main()
Persons_emplace(&vec, Person_make("Dale", "Cooper"));
// Clone/share p and q to the vector
- c_FORLIST (i, PSPtr, {p, q})
+ c_forlist (i, PSPtr, {p, q})
Persons_push(&vec, PSPtr_clone(*i.ref));
- c_FOREACH (i, Persons, vec)
+ c_foreach (i, Persons, vec)
printf("%s %s\n", cstr_str(&i.ref->get->name), cstr_str(&i.ref->get->last));
puts("");
// Look-up Audrey!
- c_WITH (Person a = Person_make("Audrey", "Home"), Person_drop(&a)) {
+ c_with (Person a = Person_make("Audrey", "Home"), Person_drop(&a)) {
const PSPtr *v = Persons_get(&vec, a);
if (v) printf("found: %s %s\n", cstr_str(&v->get->name), cstr_str(&v->get->last));
}
diff --git a/misc/examples/phonebook.c b/misc/examples/phonebook.c
index d0bc5b3a..ec9c5876 100644
--- a/misc/examples/phonebook.c
+++ b/misc/examples/phonebook.c
@@ -32,28 +32,20 @@
void print_phone_book(cmap_str phone_book)
{
- c_FOREACH (i, cmap_str, phone_book)
+ c_foreach (i, cmap_str, phone_book)
printf("%s\t- %s\n", cstr_str(&i.ref->first), cstr_str(&i.ref->second));
}
int main(int argc, char **argv)
{
- c_AUTO (cset_str, names) {
- c_FORLIST (i, const char*, {"Hello", "Cool", "True"})
- cset_str_emplace(&names, *i.ref);
-
- c_FOREACH (i, cset_str, names)
- printf("%s ", cstr_str(i.ref));
- puts("");
- }
-
- c_AUTO (cmap_str, phone_book) {
- c_FORLIST (i, cmap_str_raw, {
+ c_auto (cmap_str, phone_book)
+ {
+ phone_book = c_make(cmap_str, {
{"Lilia Friedman", "(892) 670-4739"},
{"Tariq Beltran", "(489) 600-7575"},
{"Laiba Juarez", "(303) 885-5692"},
{"Elliott Mooney", "(945) 616-4482"},
- }) cmap_str_emplace(&phone_book, c_PAIR(i.ref));
+ });
printf("Phone book:\n");
print_phone_book(phone_book);
diff --git a/misc/examples/prime.c b/misc/examples/prime.c
index 11c1f1c7..4a3b8498 100644
--- a/misc/examples/prime.c
+++ b/misc/examples/prime.c
@@ -30,7 +30,7 @@ int main(void)
printf("computing prime numbers up to %" c_ZI "\n", n);
clock_t t1 = clock();
- c_WITH (cbits primes = sieveOfEratosthenes(n + 1), cbits_drop(&primes)) {
+ c_with (cbits primes = sieveOfEratosthenes(n + 1), cbits_drop(&primes)) {
puts("done");
intptr_t np = cbits_count(&primes);
clock_t t2 = clock();
@@ -38,13 +38,13 @@ int main(void)
printf("number of primes: %" c_ZI ", time: %f\n", np, (float)(t2 - t1) / (float)CLOCKS_PER_SEC);
puts("Show all the primes in the range [2, 1000):");
printf("2");
- c_FORRANGE (i, 3, 1000, 2)
+ c_forrange (i, 3, 1000, 2)
if (cbits_test(&primes, i>>1)) printf(" %lld", i);
puts("");
puts("Show the last 50 primes using a temporary crange generator:");
crange R = crange_make(n - 1, 0, -2);
- c_FORFILTER (i, crange, R
+ c_forfilter (i, crange, R
, cbits_test(&primes, *i.ref>>1)
, c_flt_take(i, 50)) {
printf("%lld ", *i.ref);
diff --git a/misc/examples/printspan.c b/misc/examples/printspan.c
index 82b54367..c7b0c609 100644
--- a/misc/examples/printspan.c
+++ b/misc/examples/printspan.c
@@ -16,16 +16,16 @@ using_cspan(intspan, int, 1);
void printMe(intspan container) {
printf("%d:", (int)cspan_size(&container));
- c_FOREACH (e, intspan, container) printf(" %d", *e.ref);
+ c_foreach (e, intspan, container) printf(" %d", *e.ref);
puts("");
}
int main()
{
- c_AUTO (cvec_int, vec)
- c_AUTO (cstack_int, stk)
- c_AUTO (cdeq_int, deq)
- c_AUTO (cset_str, set)
+ c_auto (cvec_int, vec)
+ c_auto (cstack_int, stk)
+ c_auto (cdeq_int, deq)
+ c_auto (cset_str, set)
{
intspan sp1 = cspan_make(intspan, {1, 2});
printMe( sp1 );
@@ -36,7 +36,7 @@ int main()
intspan sp2 = cspan_from_array(arr);
printMe( (intspan)cspan_subspan(&sp2, 1, 4) );
- c_FORLIST (i, int, {1, 2, 3, 4, 5})
+ c_forlist (i, int, {1, 2, 3, 4, 5})
cvec_int_push(&vec, *i.ref);
printMe( (intspan)cspan_from(&vec) );
@@ -50,7 +50,7 @@ int main()
set = c_make(cset_str, {"1", "2", "3", "4", "5", "6", "7", "8", "9"});
printf("%d:", (int)cset_str_size(&set));
- c_FOREACH (e, cset_str, set)
+ c_foreach (e, cset_str, set)
printf(" %s", cstr_str(e.ref));
puts("");
}
diff --git a/misc/examples/priority.c b/misc/examples/priority.c
index f39c0634..0a1d419b 100644
--- a/misc/examples/priority.c
+++ b/misc/examples/priority.c
@@ -12,22 +12,22 @@ int main() {
intptr_t N = 10000000;
stc64_t rng = stc64_new((uint64_t)time(NULL));
stc64_uniform_t dist = stc64_uniform_new(0, N * 10);
- c_AUTO (cpque_i, heap)
+ c_auto (cpque_i, heap)
{
// Push ten million random numbers to priority queue
printf("Push %" c_ZI " numbers\n", N);
- c_FORRANGE (N)
+ c_forrange (N)
cpque_i_push(&heap, stc64_uniform(&rng, &dist));
// push some negative numbers too.
- c_FORLIST (i, int, {-231, -32, -873, -4, -343})
+ c_forlist (i, int, {-231, -32, -873, -4, -343})
cpque_i_push(&heap, *i.ref);
- c_FORRANGE (N)
+ c_forrange (N)
cpque_i_push(&heap, stc64_uniform(&rng, &dist));
puts("Extract the hundred smallest.");
- c_FORRANGE (100) {
+ c_forrange (100) {
printf("%" PRId64 " ", *cpque_i_top(&heap));
cpque_i_pop(&heap);
}
diff --git a/misc/examples/queue.c b/misc/examples/queue.c
index ee537b58..4064cc77 100644
--- a/misc/examples/queue.c
+++ b/misc/examples/queue.c
@@ -11,15 +11,15 @@ int main() {
stc64_t rng = stc64_new(1234);
dist = stc64_uniform_new(0, n);
- c_AUTO (cqueue_i, queue)
+ c_auto (cqueue_i, queue)
{
// Push ten million random numbers onto the queue.
- c_FORRANGE (n)
+ c_forrange (n)
cqueue_i_push(&queue, (int)stc64_uniform(&rng, &dist));
// Push or pop on the queue ten million times
printf("%d\n", n);
- c_FORRANGE (n) { // forrange uses initial n only.
+ c_forrange (n) { // forrange uses initial n only.
int r = (int)stc64_uniform(&rng, &dist);
if (r & 1)
++n, cqueue_i_push(&queue, r);
diff --git a/misc/examples/random.c b/misc/examples/random.c
index fc4576dd..e27279a0 100644
--- a/misc/examples/random.c
+++ b/misc/examples/random.c
@@ -14,7 +14,7 @@ int main()
printf("Compare speed of full and unbiased ranged random numbers...\n");
sum = 0;
before = clock();
- c_FORRANGE (N) {
+ c_forrange (N) {
sum += (uint32_t)stc64_rand(&rng);
}
diff = clock() - before;
@@ -25,7 +25,7 @@ int main()
rng = stc64_new(seed);
sum = 0;
before = clock();
- c_FORRANGE (N) {
+ c_forrange (N) {
sum += stc64_uniform(&rng, &dist1); // unbiased
}
diff = clock() - before;
@@ -35,7 +35,7 @@ int main()
sum = 0;
rng = stc64_new(seed);
before = clock();
- c_FORRANGE (N) {
+ c_forrange (N) {
sum += (int64_t)(stc64_rand(&rng) % (range + 1)); // biased
}
diff = clock() - before;
diff --git a/misc/examples/rawptr_elements.c b/misc/examples/rawptr_elements.c
index 6fb9208c..4b3d2056 100644
--- a/misc/examples/rawptr_elements.c
+++ b/misc/examples/rawptr_elements.c
@@ -28,8 +28,8 @@ typedef int64_t inttype;
int main()
{
- c_AUTO (SIPtrMap, map, m1)
- c_AUTO (SIBoxMap, m2)
+ c_auto (SIPtrMap, map, m1)
+ c_auto (SIBoxMap, m2)
{
printf("\nMap with pointer elements:\n");
SIPtrMap_insert(&map, cstr_from("testing"), c_new(inttype, 1));
@@ -41,14 +41,14 @@ int main()
m1 = SIPtrMap_clone(map);
- c_FORPAIR (name, number, SIPtrMap, m1)
+ c_forpair (name, number, SIPtrMap, m1)
printf("%s: %" PRId64 "\n", cstr_str(_.name), **_.number);
puts("\nIBox map:");
SIBoxMap_insert(&m2, cstr_from("Hello"), IBox_make(123));
SIBoxMap_emplace(&m2, "World", 999);
- c_FORPAIR (name, number, SIBoxMap, m2)
+ c_forpair (name, number, SIBoxMap, m2)
printf("%s: %d\n", cstr_str(_.name), *_.number->get);
puts("");
}
diff --git a/misc/examples/read.c b/misc/examples/read.c
index ee5dd377..4efdcfeb 100644
--- a/misc/examples/read.c
+++ b/misc/examples/read.c
@@ -6,8 +6,8 @@
cvec_str read_file(const char* name)
{
cvec_str vec = cvec_str_init();
- c_WITH (FILE* f = fopen(name, "r"), fclose(f))
- c_WITH (cstr line = cstr_NULL, cstr_drop(&line))
+ c_with (FILE* f = fopen(name, "r"), fclose(f))
+ c_with (cstr line = cstr_NULL, cstr_drop(&line))
while (cstr_getline(&line, f))
cvec_str_push(&vec, cstr_clone(line));
return vec;
@@ -16,8 +16,8 @@ cvec_str read_file(const char* name)
int main()
{
int n = 0;
- c_WITH (cvec_str vec = read_file(__FILE__), cvec_str_drop(&vec))
- c_FOREACH (i, cvec_str, vec)
+ c_with (cvec_str vec = read_file(__FILE__), cvec_str_drop(&vec))
+ c_foreach (i, cvec_str, vec)
printf("%5d: %s\n", ++n, cstr_str(i.ref));
if (errno)
diff --git a/misc/examples/regex1.c b/misc/examples/regex1.c
index ae00b71c..c311e455 100644
--- a/misc/examples/regex1.c
+++ b/misc/examples/regex1.c
@@ -7,8 +7,8 @@ int main(int argc, char* argv[])
printf("Usage: regex1 -i\n");
return 0;
}
- c_AUTO (cstr, input)
- c_AUTO (cregex, float_expr)
+ c_auto (cstr, input)
+ c_auto (cregex, float_expr)
{
int res = cregex_compile(&float_expr, "^[+-]?[0-9]+((\\.[0-9]*)?|\\.[0-9]+)$");
// Until "q" is given, ask for another number
diff --git a/misc/examples/regex2.c b/misc/examples/regex2.c
index 296d4135..4c58f3ba 100644
--- a/misc/examples/regex2.c
+++ b/misc/examples/regex2.c
@@ -15,8 +15,8 @@ int main()
{"\\p{Han}+", "This is Han: 王明:那是杂志吗?"},
};
- c_AUTO (cregex, re)
- c_FORRANGE (i, c_ARRAYLEN(s))
+ c_auto (cregex, re)
+ c_forrange (i, c_ARRAYLEN(s))
{
int res = cregex_compile(&re, s[i].pattern);
if (res < 0) {
@@ -25,8 +25,8 @@ int main()
}
printf("\ninput: %s\n", s[i].input);
- c_FORMATCH (j, &re, s[i].input) {
- c_FORRANGE (k, cregex_captures(&re))
+ c_formatch (j, &re, s[i].input) {
+ c_forrange (k, cregex_captures(&re))
printf(" submatch %lld: %.*s\n", k, c_SVARG(j.match[k]));
}
}
diff --git a/misc/examples/regex_match.c b/misc/examples/regex_match.c
index b7d6ed3a..dcc19c1f 100644
--- a/misc/examples/regex_match.c
+++ b/misc/examples/regex_match.c
@@ -13,19 +13,19 @@ int main()
" Boltzmann const: 1.38064852E-23, is very small."
" Bohrradius is 5.29177210903e-11, and Avogadros number is 6.02214076e23.";
- c_AUTO (cregex, re)
- c_AUTO (cstack_float, vec)
- c_AUTO (cstr, nums)
+ c_auto (cregex, re)
+ c_auto (cstack_float, vec)
+ c_auto (cstr, nums)
{
const char* pattern = "[+-]?([0-9]*\\.)?\\d+([Ee][+-]?\\d+)?";
int res = cregex_compile(&re, pattern);
printf("%d: %s\n", res, pattern);
// extract and convert all numbers in str to floats
- c_FORMATCH (i, &re, str)
+ c_formatch (i, &re, str)
cstack_float_push(&vec, (float)atof(i.match[0].str));
- c_FOREACH (i, cstack_float, vec)
+ c_foreach (i, cstack_float, vec)
printf(" %g\n", *i.ref);
// extracts the numbers only to a comma separated string.
diff --git a/misc/examples/regex_replace.c b/misc/examples/regex_replace.c
index ec38ca56..ebb57488 100644
--- a/misc/examples/regex_replace.c
+++ b/misc/examples/regex_replace.c
@@ -17,7 +17,7 @@ int main()
const char* pattern = "\\b(\\d\\d\\d\\d)-(1[0-2]|0[1-9])-(3[01]|[12][0-9]|0[1-9])\\b";
const char* input = "start date: 2015-12-31, end date: 2022-02-28";
- c_AUTO (cstr, str)
+ c_auto (cstr, str)
{
printf("INPUT: %s\n", input);
@@ -34,9 +34,9 @@ int main()
printf("brack: %s\n", cstr_str(&str));
/* Shows how to compile RE separately */
- c_WITH (cregex re = cregex_from(pattern), cregex_drop(&re)) {
+ c_with (cregex re = cregex_from(pattern), cregex_drop(&re)) {
if (cregex_captures(&re) == 0)
- continue; /* break c_WITH */
+ continue; /* break c_with */
/* European date format. */
cstr_take(&str, cregex_replace(&re, input, "$3.$2.$1"));
printf("euros: %s\n", cstr_str(&str));
diff --git a/misc/examples/replace.c b/misc/examples/replace.c
index ca305ecd..15cf3bae 100644
--- a/misc/examples/replace.c
+++ b/misc/examples/replace.c
@@ -11,7 +11,7 @@ int main ()
// Ustring positions: 0123456789*123456789*12345
cstr s = cstr_from(base); // "this is a test string."
cstr m = cstr_clone(s);
- c_DEFER (cstr_drop(&s), cstr_drop(&m)) {
+ c_defer (cstr_drop(&s), cstr_drop(&m)) {
cstr_append(&m, cstr_str(&m));
cstr_append(&m, cstr_str(&m));
printf("%s\n", cstr_str(&m));
diff --git a/misc/examples/shape.c b/misc/examples/shape.c
index f71704d9..d290fb4d 100644
--- a/misc/examples/shape.c
+++ b/misc/examples/shape.c
@@ -111,7 +111,7 @@ static void Polygon_draw(const Shape* shape)
{
const Polygon* self = c_dyn_cast(Polygon, shape);
printf("Polygon :");
- c_FOREACH (i, PointVec, self->points)
+ c_foreach (i, PointVec, self->points)
printf(" (%g,%g)", i.ref->x, i.ref->y);
puts("");
}
@@ -138,23 +138,23 @@ void testShape(const Shape* shape)
int main(void)
{
- c_AUTO (Shapes, shapes)
+ c_auto (Shapes, shapes)
{
Triangle* tri1 = c_new(Triangle, Triangle_from((Point){5, 7}, (Point){12, 7}, (Point){12, 20}));
Polygon* pol1 = c_new(Polygon, Polygon_init());
Polygon* pol2 = c_new(Polygon, Polygon_init());
- c_FORLIST (i, Point, {{50, 72}, {123, 73}, {127, 201}, {828, 333}})
+ c_forlist (i, Point, {{50, 72}, {123, 73}, {127, 201}, {828, 333}})
Polygon_addPoint(pol1, *i.ref);
- c_FORLIST (i, Point, {{5, 7}, {12, 7}, {12, 20}, {82, 33}, {17, 56}})
+ c_forlist (i, Point, {{5, 7}, {12, 7}, {12, 20}, {82, 33}, {17, 56}})
Polygon_addPoint(pol2, *i.ref);
Shapes_push(&shapes, &tri1->shape);
Shapes_push(&shapes, &pol1->shape);
Shapes_push(&shapes, &pol2->shape);
- c_FOREACH (i, Shapes, shapes)
+ c_foreach (i, Shapes, shapes)
testShape(*i.ref);
}
}
diff --git a/misc/examples/sidebyside.cpp b/misc/examples/sidebyside.cpp
index 11328668..80c934a4 100644
--- a/misc/examples/sidebyside.cpp
+++ b/misc/examples/sidebyside.cpp
@@ -25,13 +25,13 @@ int main() {
std::cout << std::endl;
}
- c_AUTO (IIMap, hist)
+ c_auto (IIMap, hist)
{
IIMap_insert(&hist, 12, 100).ref->second += 1;
IIMap_insert(&hist, 13, 100).ref->second += 1;
IIMap_insert(&hist, 12, 100).ref->second += 1;
- c_FOREACH (i, IIMap, hist)
+ c_foreach (i, IIMap, hist)
printf("%d, %d\n", i.ref->first, i.ref->second);
puts("");
}
@@ -45,12 +45,12 @@ int main() {
std::cout << std::endl;
}
- c_AUTO (SIMap, food)
+ c_auto (SIMap, food)
{
- c_FORLIST (i, SIMap_raw, {{"burger", 5}, {"pizza", 12}, {"steak", 15}})
+ c_forlist (i, SIMap_raw, {{"burger", 5}, {"pizza", 12}, {"steak", 15}})
SIMap_emplace(&food, c_PAIR(i.ref));
- c_FOREACH (i, SIMap, food)
+ c_foreach (i, SIMap, food)
printf("%s, %d\n", cstr_str(&i.ref->first), i.ref->second);
puts("");
}
diff --git a/misc/examples/sorted_map.c b/misc/examples/sorted_map.c
index 47509edb..c4a05c76 100644
--- a/misc/examples/sorted_map.c
+++ b/misc/examples/sorted_map.c
@@ -9,7 +9,7 @@ int main()
{
// empty map containers
- c_AUTO (csmap_int, gquiz1, gquiz2)
+ c_auto (csmap_int, gquiz1, gquiz2)
{
// insert elements in random order
csmap_int_insert(&gquiz1, 2, 30);
@@ -22,17 +22,17 @@ int main()
// printing map gquiz1
printf("\nThe map gquiz1 is :\n\tKEY\tELEMENT\n");
- c_FOREACH (itr, csmap_int, gquiz1)
+ c_foreach (itr, csmap_int, gquiz1)
printf("\t%d\t%d\n", itr.ref->first, itr.ref->second);
printf("\n");
// assigning the elements from gquiz1 to gquiz2
- c_FOREACH (i, csmap_int, gquiz1)
+ c_foreach (i, csmap_int, gquiz1)
csmap_int_insert(&gquiz2, i.ref->first, i.ref->second);
// print all elements of the map gquiz2
printf("\nThe map gquiz2 is :\n\tKEY\tELEMENT\n");
- c_FOREACH (itr, csmap_int, gquiz2)
+ c_foreach (itr, csmap_int, gquiz2)
printf("\t%d\t%d\n", itr.ref->first, itr.ref->second);
printf("\n");
@@ -41,7 +41,7 @@ int main()
printf("\tKEY\tELEMENT\n");
csmap_int_erase_range(&gquiz2, csmap_int_begin(&gquiz2),
csmap_int_find(&gquiz2, 3));
- c_FOREACH (itr, csmap_int, gquiz2)
+ c_foreach (itr, csmap_int, gquiz2)
printf("\t%d\t%d\n", itr.ref->first, itr.ref->second);
printf("\n");
@@ -49,7 +49,7 @@ int main()
int num = csmap_int_erase(&gquiz2, 4);
printf("\ngquiz2.erase(4) : %d removed\n", num);
printf("\tKEY\tELEMENT\n");
- c_FOREACH (itr, csmap_int, gquiz2)
+ c_foreach (itr, csmap_int, gquiz2)
printf("\t%d\t%d\n", itr.ref->first, itr.ref->second);
printf("\n");
diff --git a/misc/examples/splitstr.c b/misc/examples/splitstr.c
index 43309634..4705696c 100644
--- a/misc/examples/splitstr.c
+++ b/misc/examples/splitstr.c
@@ -5,15 +5,15 @@
int main()
{
- puts("Split with c_FORTOKEN (csview):");
+ puts("Split with c_fortoken (csview):");
- c_FORTOKEN (i, "Hello World C99!", " ")
+ c_fortoken (i, "Hello World C99!", " ")
printf("'%.*s'\n", c_SVARG(i.token));
- puts("\nSplit with c_FORMATCH (regex):");
+ puts("\nSplit with c_formatch (regex):");
- c_WITH (cregex re = cregex_from("[^ ]+"), cregex_drop(&re))
- c_FORMATCH (i, &re, " Hello World C99! ")
+ c_with (cregex re = cregex_from("[^ ]+"), cregex_drop(&re))
+ c_formatch (i, &re, " Hello World C99! ")
printf("'%.*s'\n", c_SVARG(i.match[0]));
}
diff --git a/misc/examples/sso_map.c b/misc/examples/sso_map.c
index 0841a316..128cf50d 100644
--- a/misc/examples/sso_map.c
+++ b/misc/examples/sso_map.c
@@ -5,11 +5,11 @@
int main()
{
- c_AUTO (cmap_str, m) {
+ c_auto (cmap_str, m) {
cmap_str_emplace(&m, "Test short", "This is a short string");
cmap_str_emplace(&m, "Test long ", "This is a longer string");
- c_FORPAIR (k, v, cmap_str, m)
+ c_forpair (k, v, cmap_str, m)
printf("%s: '%s' Len=%" c_ZI ", Is long: %s\n",
cstr_str(_.k), cstr_str(_.v), cstr_size(_.v),
cstr_is_long(_.v) ? "true" : "false");
diff --git a/misc/examples/stack.c b/misc/examples/stack.c
index 86099607..50dc8eb7 100644
--- a/misc/examples/stack.c
+++ b/misc/examples/stack.c
@@ -11,18 +11,18 @@
#include <stc/cstack.h>
int main() {
- c_AUTO (cstack_i, stack)
- c_AUTO (cstack_c, chars)
+ c_auto (cstack_i, stack)
+ c_auto (cstack_c, chars)
{
- c_FORRANGE (i, 101)
+ c_forrange (i, 101)
cstack_i_push(&stack, (int)(i*i));
printf("%d\n", *cstack_i_top(&stack));
- c_FORRANGE (i, 90)
+ c_forrange (i, 90)
cstack_i_pop(&stack);
- c_FOREACH (i, cstack_i, stack)
+ c_foreach (i, cstack_i, stack)
printf(" %d", *i.ref);
puts("");
printf("top: %d\n", *cstack_i_top(&stack));
diff --git a/misc/examples/sview_split.c b/misc/examples/sview_split.c
index 77caf640..2bb7aaee 100644
--- a/misc/examples/sview_split.c
+++ b/misc/examples/sview_split.c
@@ -12,7 +12,7 @@ int main()
printf("%.*s, %.*s, %.*s\n", c_SVARG(year), c_SVARG(month), c_SVARG(day));
- c_AUTO (cstr, y, m, d) {
+ c_auto (cstr, y, m, d) {
y = cstr_from_sv(year), m = cstr_from_sv(month), d = cstr_from_sv(day);
printf("%s, %s, %s\n", cstr_str(&y), cstr_str(&m), cstr_str(&d));
}
diff --git a/misc/examples/unordered_set.c b/misc/examples/unordered_set.c
index bf054b88..f9221b21 100644
--- a/misc/examples/unordered_set.c
+++ b/misc/examples/unordered_set.c
@@ -7,7 +7,7 @@
int main()
{
// declaring set for storing string data-type
- c_AUTO (cset_str, stringSet)
+ c_auto (cset_str, stringSet)
{
// inserting various string, same string will be stored
// once in set
@@ -36,7 +36,7 @@ int main()
// now iterating over whole set and printing its
// content
printf("All elements :\n");
- c_FOREACH (itr, cset_str, stringSet)
+ c_foreach (itr, cset_str, stringSet)
printf("%s\n", cstr_str(itr.ref));
}
}
diff --git a/misc/examples/utf8replace_c.c b/misc/examples/utf8replace_c.c
index 035c5b00..adb8c042 100644
--- a/misc/examples/utf8replace_c.c
+++ b/misc/examples/utf8replace_c.c
@@ -1,7 +1,9 @@
#include <stc/cstr.h>
-int main() {
- c_AUTO (cstr, hello, str) {
+int main()
+{
+ c_auto (cstr, hello, str)
+ {
hello = cstr_lit("hell😀 w😀rld");
printf("%s\n", cstr_str(&hello));
@@ -13,7 +15,7 @@ int main() {
);
printf("%s\n", cstr_str(&hello));
- c_FOREACH (c, cstr, hello)
+ c_foreach (c, cstr, hello)
printf("%.*s,", c_SVARG(c.u8.chr));
str = cstr_lit("scooby, dooby doo");
diff --git a/misc/examples/vikings.c b/misc/examples/vikings.c
index 86d60519..7a21d0a5 100644
--- a/misc/examples/vikings.c
+++ b/misc/examples/vikings.c
@@ -50,7 +50,7 @@ static inline RViking Viking_toraw(const Viking* vp) {
int main()
{
- c_AUTO (Vikings, vikings) {
+ c_auto (Vikings, vikings) {
Vikings_emplace(&vikings, (RViking){"Einar", "Norway"}, 20);
Vikings_emplace(&vikings, (RViking){"Olaf", "Denmark"}, 24);
Vikings_emplace(&vikings, (RViking){"Harald", "Iceland"}, 12);
@@ -59,7 +59,7 @@ int main()
Vikings_value* v = Vikings_get_mut(&vikings, (RViking){"Einar", "Norway"});
v->second += 3; // add 3 hp points to Einar
- c_FORPAIR (vk, hp, Vikings, vikings) {
+ c_forpair (vk, hp, Vikings, vikings) {
printf("%s of %s has %d hp\n", cstr_str(&_.vk->name), cstr_str(&_.vk->country), *_.hp);
}
}
diff --git a/misc/examples/words.c b/misc/examples/words.c
index b945092f..f097a991 100644
--- a/misc/examples/words.c
+++ b/misc/examples/words.c
@@ -10,19 +10,19 @@
int main1()
{
- c_AUTO (cvec_str, words)
- c_AUTO (cmap_str, word_map)
+ c_auto (cvec_str, words)
+ c_auto (cmap_str, word_map)
{
- c_FORLIST (i, const char*, {
+ words = c_make(cvec_str, {
"this", "sentence", "is", "not", "a", "sentence",
"this", "sentence", "is", "a", "hoax"
- }) cvec_str_emplace_back(&words, *i.ref);
+ });
- c_FOREACH (w, cvec_str, words) {
+ c_foreach (w, cvec_str, words) {
cmap_str_emplace(&word_map, cstr_str(w.ref), 0).ref->second += 1;
}
- c_FOREACH (i, cmap_str, word_map) {
+ c_foreach (i, cmap_str, word_map) {
printf("%d occurrences of word '%s'\n",
i.ref->second, cstr_str(&i.ref->first));
}
diff --git a/misc/tests/cregex_test.c b/misc/tests/cregex_test.c
index ac7e958f..b3cc9f0a 100644
--- a/misc/tests/cregex_test.c
+++ b/misc/tests/cregex_test.c
@@ -45,7 +45,7 @@ CTEST(cregex, compile_match_anchors)
CTEST(cregex, compile_match_quantifiers1)
{
const char* inp;
- c_AUTO (cregex, re) {
+ c_auto (cregex, re) {
re = cregex_from("ä+");
ASSERT_EQ(re.error, 0);
@@ -65,7 +65,7 @@ CTEST(cregex, compile_match_quantifiers1)
CTEST(cregex, compile_match_quantifiers2)
{
const char* inp;
- c_AUTO (cregex, re) {
+ c_auto (cregex, re) {
re = cregex_from("bä*");
ASSERT_EQ(re.error, 0);
@@ -98,7 +98,7 @@ CTEST(cregex, compile_match_escaped_chars)
CTEST(cregex, compile_match_class_simple)
{
- c_AUTO (cregex, re1, re2, re3)
+ c_auto (cregex, re1, re2, re3)
{
re1 = cregex_from("\\s");
ASSERT_EQ(re1.error, 0);
@@ -123,7 +123,7 @@ CTEST(cregex, compile_match_class_simple)
CTEST(cregex, compile_match_or)
{
- c_AUTO (cregex, re, re2)
+ c_auto (cregex, re, re2)
{
re = cregex_from("as|df");
ASSERT_EQ(re.error, 0);
@@ -185,7 +185,7 @@ CTEST(cregex, compile_match_cap)
CTEST(cregex, search_all)
{
const char* inp;
- c_AUTO (cregex, re)
+ c_auto (cregex, re)
{
re = cregex_from("ab");
csview m = {0};
@@ -206,7 +206,7 @@ CTEST(cregex, search_all)
CTEST(cregex, captures_len)
{
- c_AUTO (cregex, re) {
+ c_auto (cregex, re) {
re = cregex_from("(ab(cd))(ef)");
ASSERT_EQ(cregex_captures(&re), 4);
}
@@ -215,7 +215,7 @@ CTEST(cregex, captures_len)
CTEST(cregex, captures_cap)
{
const char* inp;
- c_AUTO (cregex, re) {
+ c_auto (cregex, re) {
re = cregex_from("(ab)((cd)+)");
ASSERT_EQ(cregex_captures(&re), 4);
@@ -249,7 +249,7 @@ CTEST(cregex, replace)
const char* pattern = "\\b(\\d\\d\\d\\d)-(1[0-2]|0[1-9])-(3[01]|[12][0-9]|0[1-9])\\b";
const char* input = "start date: 2015-12-31, end date: 2022-02-28";
- c_AUTO (cstr, str) {
+ c_auto (cstr, str) {
// replace with a fixed string, extended all-in-one call:
cstr_take(&str, cregex_replace_pattern(pattern, input, "YYYY-MM-DD"));
ASSERT_STREQ(cstr_str(&str), "start date: YYYY-MM-DD, end date: YYYY-MM-DD");
@@ -267,7 +267,7 @@ CTEST(cregex, replace)
ASSERT_STREQ(cstr_str(&str), "52 ${apples} ${and} 31 ${mangoes}");
// Compile RE separately
- c_WITH (cregex re = cregex_from(pattern), cregex_drop(&re)) {
+ c_with (cregex re = cregex_from(pattern), cregex_drop(&re)) {
ASSERT_EQ(cregex_captures(&re), 4);
// European date format.
diff --git a/misc/tests/cspan_test.c b/misc/tests/cspan_test.c
index 9e33467c..5d46f579 100644
--- a/misc/tests/cspan_test.c
+++ b/misc/tests/cspan_test.c
@@ -47,9 +47,9 @@ CTEST(cspan, slice) {
#include <stc/cstack.h>
CTEST(cspan, slice2) {
- c_AUTO (cstack_int, stack)
+ c_auto (cstack_int, stack)
{
- c_FORRANGE (i, 10*20*30)
+ c_forrange (i, 10*20*30)
cstack_int_push(&stack, i);
intspan3 ms3 = cspan_md(stack.data, 10, 20, 30);
@@ -66,7 +66,7 @@ CTEST(cspan, slice2) {
ASSERT_EQ(65112, sum);
sum = 0;
- c_FOREACH (i, intspan3, ms3)
+ c_foreach (i, intspan3, ms3)
sum += *i.ref;
ASSERT_EQ(65112, sum);
}
@@ -89,14 +89,14 @@ CTEST_SETUP(cspan_cube) {
_self->tiles = Tiles_init();
cstack_int_reserve(&_self->stack, N);
- c_FORRANGE (i, N)
+ c_forrange (i, N)
cstack_int_push(&_self->stack, i+1);
intspan3 ms3 = cspan_md(_self->stack.data, CUBE, CUBE, CUBE);
- c_FORRANGE (i, 0, ms3.shape[0], TSIZE) {
- c_FORRANGE (j, 0, ms3.shape[1], TSIZE) {
- c_FORRANGE (k, 0, ms3.shape[2], TSIZE) {
+ c_forrange (i, 0, ms3.shape[0], TSIZE) {
+ c_forrange (j, 0, ms3.shape[1], TSIZE) {
+ c_forrange (k, 0, ms3.shape[2], TSIZE) {
intspan3 tile = cspan_slice(intspan3, &ms3, {i, i + TSIZE}, {j, j + TSIZE}, {k, k + TSIZE});
Tiles_push(&_self->tiles, tile);
}
@@ -117,8 +117,8 @@ CTEST_F(cspan_cube, slice3) {
int64_t sum = 0;
// iterate each 3d tile in sequence
- c_FOREACH (i, Tiles, _self->tiles)
- c_FOREACH (t, intspan3, *i.ref)
+ c_foreach (i, Tiles, _self->tiles)
+ c_foreach (t, intspan3, *i.ref)
sum += *t.ref;
ASSERT_EQ(n*(n + 1)/2, sum);
diff --git a/src/checkauto.l b/src/checkauto.l
index 4af35c49..3bb536a1 100644
--- a/src/checkauto.l
+++ b/src/checkauto.l
@@ -1,4 +1,4 @@
-/* Check for illegal return/break/continue usage inside a STC-lib c_AUTO* block (RAII).
+/* Check for illegal return/break/continue usage inside a STC-lib c_auto* block (RAII).
* Copyright Tyge Løvset, (c) 2023.
*/
%{
@@ -38,13 +38,13 @@ c_forfilter |
c_forwhile |
c_formatch |
c_fortoken |
-c_FOREACH |
-c_FORPAIR |
-c_FORRANGE |
-c_FORFILTER |
-c_FORWHILE |
-c_FORMATCH |
-c_FORTOKEN |
+c_foreach |
+c_forpair |
+c_forrange |
+c_forfilter |
+c_forwhile |
+c_formatch |
+c_fortoken |
for |
while |
switch { block_type |= LOOP; state = BRACES; }
@@ -53,10 +53,10 @@ c_with |
c_scope |
c_defer |
c_auto |
-c_WITH |
-c_SCOPE |
-c_DEFER |
-c_AUTO { block_type = AUTO; state = BRACES; }
+c_with |
+c_scope |
+c_defer |
+c_auto { block_type = AUTO; state = BRACES; }
\( { if (state == BRACES) ++braces_lev; }
\) { if (state == BRACES && --braces_lev == 0) {
state = BRACESDONE;
@@ -64,8 +64,8 @@ c_AUTO { block_type = AUTO; state = BRACES; }
}
if { if (state == BRACESDONE) {
if (block_type == AUTO) {
- printf("%s:%d: warning: 'if' after c_AUTO* not enclosed in curly braces.\n"
- " Make sure to enclose 'if - else' statement in { } after c_AUTO*.\n",
+ printf("%s:%d: warning: 'if' after c_auto* not enclosed in curly braces.\n"
+ " Make sure to enclose 'if - else' statement in { } after c_auto*.\n",
fname, yylineno);
++warnings;
}
@@ -81,20 +81,20 @@ if { if (state == BRACESDONE) {
\{ { if (state != BRACES) { block[++block_lev] = block_type; state = NORMAL; } }
\} { if (state != BRACES) block_type = block[--block_lev]; }
return { if (block_type == AUTO) {
- printf("%s:%d: error: 'return' used inside a c_AUTO* scope.\n"
- " Use 'continue' to exit the current c_AUTO* scope before return.\n"
+ printf("%s:%d: error: 'return' used inside a c_auto* scope.\n"
+ " Use 'continue' to exit the current c_auto* scope before return.\n"
, fname, yylineno);
++errors;
} else if (block_type & AUTO) {
- printf("%s:%d: error: 'return' used in a loop inside a c_AUTO* scope.\n"
- " Use 'break' to exit loop, then 'continue' to exit c_AUTO*.\n"
+ printf("%s:%d: error: 'return' used in a loop inside a c_auto* scope.\n"
+ " Use 'break' to exit loop, then 'continue' to exit c_auto*.\n"
, fname, yylineno);
++errors;
}
}
break { if (block_type == AUTO) {
- printf("%s:%d: error: 'break' used inside a c_AUTO* scope.\n"
- " Use 'continue' to exit the current c_AUTO* scope.\n"
+ printf("%s:%d: error: 'break' used inside a c_auto* scope.\n"
+ " Use 'continue' to exit the current c_auto* scope.\n"
, fname, yylineno);
++errors;
}