diff options
| author | Tyge Lovset <[email protected]> | 2021-09-20 10:36:25 +0200 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2021-09-20 10:36:25 +0200 |
| commit | 0861391b9b3b8ad37e24b0dba7da192f31e48a6b (patch) | |
| tree | df78821e47690e1793465d0fcf3d068ad33ccf44 | |
| parent | 625a0fad0c1d187d56d3a9c9bb831987e9250e86 (diff) | |
| download | STC-modified-0861391b9b3b8ad37e24b0dba7da192f31e48a6b.tar.gz STC-modified-0861391b9b3b8ad37e24b0dba7da192f31e48a6b.zip | |
Renamed macros: breaking changes for Version 2.0!
c_forvar => c_autovar
c_forscope => c_autoscope
c_forauto => c_auto
Removed: c_fordefer(x); use c_forscope(0, x) instead.
Added: c_exitauto; // continue
52 files changed, 146 insertions, 152 deletions
@@ -5,10 +5,11 @@ STC - Standard Template Containers for C News
----
-**VERSION 2.X RELEASED**: This main version uses a different way to instantiate templated containers,
-and is not compatible with v1.X, however the usage is otherwise compatible with v1.X. The new style
-has multiple advantages, e.g. implementation does no longer contain long macro definitions to generate
-code. Also, specfiying template arguments is more user friendly and flexible.
+**VERSION 2.X RELEASED**: There are two main breaking changes from V1.X.
+- STC V2.X uses a different way to instantiate templated containers which is not compatible with v1.X.
+- c_forauto, c_forvar, c_forscope are now renamed to **c_auto**, **c_autovar**, and **c_autoscope**. There is also a **c_exitauto** macro, which breaks out of an auto-block. The auto name refers to the original meaning of auto keyword in C, namely automatic stack allocated variable, however now it covers automatic resource (de)allocation in general.
+
+The new teplate instantiation style has multiple advantages, e.g. implementation does not contain long macro definitions for code generation. Also, specfiying template arguments is more user friendly and flexible.
Introduction
------------
@@ -120,12 +121,12 @@ int Point_compare(const struct Point* a, const struct Point* b) { int main(void) {
// define six containers with automatic call of init and del (destruction after scope exit)
- c_forauto (cset_int, set)
- c_forauto (cvec_pnt, vec)
- c_forauto (cdeq_int, deq)
- c_forauto (clist_int, lst)
- c_forauto (cstack_int, stk)
- c_forauto (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)
{
// add some elements to each container
c_emplace(cset_int, set, {10, 20, 30});
@@ -240,8 +241,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_forvar (cvec_str vec = cvec_str_init(), cvec_str_del(&vec)) // defer vector destructor to end of block
-c_forvar (cstr s = cstr_lit("a string literal"), cstr_del(&s)) // cstr_lit() for literals; no strlen() usage
+c_autovar (cvec_str vec = cvec_str_init(), cvec_str_del(&vec)) // defer vector destructor to end of block
+c_autovar (cstr s = cstr_lit("a string literal"), cstr_del(&s)) // cstr_lit() for literals; no strlen() usage
{
const char* hello = "Hello";
cvec_str_push_back(&vec, cstr_from(hello); // construct and add string from const char*
diff --git a/benchmarks/others/old/csmap.h b/benchmarks/others/old/csmap.h index 88c3967a..4a380614 100644 --- a/benchmarks/others/old/csmap.h +++ b/benchmarks/others/old/csmap.h @@ -30,7 +30,7 @@ using_csmap(mx, int, char); // Sorted map<int, char>
int main(void) {
- c_forvar (csmap_mx m = csmap_mx_init(), csmap_mx_del(&m))
+ c_autovar (csmap_mx m = csmap_mx_init(), csmap_mx_del(&m))
{
csmap_mx_insert(&m, 5, 'a');
csmap_mx_insert(&m, 8, 'b');
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md index dc274869..75ebae2f 100644 --- a/docs/ccommon_api.md +++ b/docs/ccommon_api.md @@ -2,32 +2,32 @@ The following handy macros are safe to use, i.e. have no side-effects. -### c_forvar, c_forauto, c_forscope, c_fordefer +### c_autoscope, c_autovar, c_auto, c_exitauto General ***defer*** mechanics for resource acquisition. These macros allows to specify the release of the resource where the resource acquisition takes place. Makes it easier to verify that resources are released. -**NB**: These macros are one-time executed **for-loops**. Use ***only*** `continue` in order to break out -of these four `c_for`-blocks. ***Do not*** use `return` or `goto` (or `break`) inside them, as they will -prevent the `end`-statement to be executed when leaving scope. This is not particular to the `c_for*()` +**NB**: These macros are one-time executed **for-loops**. Use ***only*** `c_exitauto` in order to break out +of these `c_auto*`-blocks! ***Do not*** use `return` or `goto` (or `break`) inside them, as they will +prevent the `end`-statement to be executed when leaving scope. This is not particular to the `c_auto*()` macros, as one must always make sure to unwind temporary allocated resources before a `return` in C. -| Usage | Description | -|:---------------------------------------|:--------------------------------------------------| -| `c_forvar (Type var=init, end...)` | Declare `var`. Defer `end` to end of block | -| `c_forauto (Type, var...)` | `c_forvar (Type var=Type_init(), Type_del(&var))` | -| `c_forscope (start, end)` | Execute `start`. Defer `end` to end of block | -| `c_fordefer (end...)` | Defer execution of `end` to end of block | +| Usage | Description | +|:---------------------------------------|:---------------------------------------------------| +| `c_autoscope (init, end...)` | Execute `init`. Defer `end...` to end of block | +| `c_autovar (Type var=init, end...)` | Declare `var`. Defer `end...` to end of block | +| `c_auto (Type, var...)` | `c_autovar (Type var=Type_init(), Type_del(&var))` | +| `c_exitauto;` | Break out of a `c_auto*`-block/scope | -For multiple variables, use either multiple **c_forvar** in sequence, or declare variable outside -scope and use **c_forscope** or **c_fordefer**. Also, **c_forauto** support up to 3 vars. +For multiple variables, use either multiple **c_autovar** in sequence, or declare variable outside +scope and use **c_autoscope**. Also, **c_auto** support up to 3 variables. ```c -c_forvar (cstr s = cstr_lit("Hello"), cstr_del(&s)) +c_autovar (cstr s = cstr_lit("Hello"), cstr_del(&s)) { cstr_append(&s, " world"); printf("%s\n", s.str); } -c_forauto (cstr, s1, s2) +c_auto (cstr, s1, s2) { cstr_append(&s1, "Hello"); cstr_append(&s1, " world"); @@ -38,21 +38,14 @@ c_forauto (cstr, s1, s2) printf("%s %s\n", s1.str, s2.str); } -#define i_tag i32 -#define i_val int32_t -#include <stc/cvec.h> -... -cvec_i32 vec; -c_forscope (vec = cvec_i32_init(), cvec_i32_del(&vec)) +MyData data; +c_autoscope (mydata_init(&data), mydata_destroy(&data)) { - cvec_i32_push_back(&vec, 123); - cvec_i32_push_back(&vec, 321); - - c_foreach (i, cvec_i32, vec) printf(" %d", *i.ref); + printf("%s\n", mydata.name.str); } cstr s1 = cstr_lit("Hello"), s2 = cstr_lit("world"); -c_fordefer (cstr_del(&s1), cstr_del(&s2)) +c_autoscope (0, cstr_del(&s1), cstr_del(&s2)) { printf("%s %s\n", s1.str, s2.str); } @@ -70,8 +63,8 @@ cvec_str readFile(const char* name) { cvec_str vec = cvec_str_init(); // returned - c_forvar (FILE* fp = fopen(name, "r"), fclose(fp)) - c_forvar (cstr line = cstr_null, cstr_del(&line)) + c_autovar (FILE* fp = fopen(name, "r"), fclose(fp)) + c_autovar (cstr line = cstr_null, cstr_del(&line)) while (cstr_getline(&line, fp)) cvec_str_emplace_back(&vec, line.str); return vec; @@ -79,7 +72,7 @@ cvec_str readFile(const char* name) int main() { - c_forvar (cvec_str x = readFile(__FILE__), cvec_str_del(&x)) + c_autovar (cvec_str x = readFile(__FILE__), cvec_str_del(&x)) c_foreach (i, cvec_str, x) printf("%s\n", i.ref->str); } diff --git a/docs/clist_api.md b/docs/clist_api.md index 1eb92c12..b4cbced7 100644 --- a/docs/clist_api.md +++ b/docs/clist_api.md @@ -175,7 +175,7 @@ Splice `[30, 40]` from *L2* into *L1* before `3`: #include <stdio.h> int main() { - c_forauto (clist_i, L1, L2) + c_auto (clist_i, L1, L2) { c_emplace(clist_i, L1, {1, 2, 3, 4, 5}); c_emplace(clist_i, L2, {10, 20, 30, 40, 50}); diff --git a/docs/cmap_api.md b/docs/cmap_api.md index 4fee41b7..0dd19d2c 100644 --- a/docs/cmap_api.md +++ b/docs/cmap_api.md @@ -206,7 +206,7 @@ typedef struct { int x, y, z; } Vec3i; int main() { // Define map with defered destruct - c_forvar (cmap_vi vecs = cmap_vi_init(), cmap_vi_del(&vecs)) + c_autovar (cmap_vi vecs = cmap_vi_init(), cmap_vi_del(&vecs)) { cmap_vi_insert(&vecs, (Vec3i){100, 0, 0}, 1); cmap_vi_insert(&vecs, (Vec3i){ 0, 100, 0}, 2); @@ -239,7 +239,7 @@ typedef struct { int x, y, z; } Vec3i; int main() { - c_forvar (cmap_iv vecs = cmap_iv_init(), cmap_iv_del(&vecs)) + c_autovar (cmap_iv vecs = cmap_iv_init(), cmap_iv_del(&vecs)) { cmap_iv_insert(&vecs, 1, (Vec3i){100, 0, 0}); cmap_iv_insert(&vecs, 2, (Vec3i){ 0, 100, 0}); @@ -367,7 +367,7 @@ static RViking Viking_toR(const Viking* v) int main() { - c_forauto (cmap_vk, vikings) // RAII + c_auto (cmap_vk, vikings) // RAII { // Insert works as before, takes a constructed Viking object cmap_vk_insert(&vikings, (Viking){cstr_from("Einar"), cstr_from("Norway")}, 25); diff --git a/docs/cpque_api.md b/docs/cpque_api.md index 3b3338e8..990cc4b7 100644 --- a/docs/cpque_api.md +++ b/docs/cpque_api.md @@ -68,7 +68,7 @@ int main() stc64_uniform_t dist = stc64_uniform_init(0, N * 10); // Declare heap, with defered del() - c_forauto (cpque_i, heap) + c_auto (cpque_i, heap) { // Push ten million random numbers to priority queue, plus some negative ones. c_forrange (N) diff --git a/docs/csmap_api.md b/docs/csmap_api.md index a9481bf1..1e41593f 100644 --- a/docs/csmap_api.md +++ b/docs/csmap_api.md @@ -143,7 +143,7 @@ int main() {100, "Red"}, {110, "Blue"}, }); - c_fordefer (csmap_id_del(&idnames)) + c_autoscope (0, csmap_id_del(&idnames)) { // put replaces existing mapped value: csmap_id_emplace_or_assign(&idnames, 110, "White"); @@ -185,7 +185,7 @@ static int Vec3i_compare(const Vec3i* a, const Vec3i* b) { int main() { - c_forvar (csmap_vi vecs = csmap_vi_init(), csmap_vi_del(&vecs)) + c_autovar (csmap_vi vecs = csmap_vi_init(), csmap_vi_del(&vecs)) { csmap_vi_insert(&vecs, (Vec3i){100, 0, 0}, 1); csmap_vi_insert(&vecs, (Vec3i){ 0, 100, 0}, 2); @@ -218,7 +218,7 @@ typedef struct { int x, y, z; } Vec3i; int main() { - c_forvar (csmap_iv vecs = csmap_iv_init(), csmap_iv_del(&vecs)) + c_autovar (csmap_iv vecs = csmap_iv_init(), csmap_iv_del(&vecs)) { csmap_iv_insert(&vecs, 1, (Vec3i){100, 0, 0}); csmap_iv_insert(&vecs, 2, (Vec3i){ 0, 100, 0}); diff --git a/docs/csptr_api.md b/docs/csptr_api.md index ce70d3c8..67a67d5c 100644 --- a/docs/csptr_api.md +++ b/docs/csptr_api.md @@ -83,8 +83,8 @@ void int_del(int* x) { int main() { - c_forauto (cvec_int, vec) // declare and init vec, call del at scope exit - c_forauto (csset_int, set) // declare and init set, call del at scope exit + c_auto (cvec_int, vec) // declare and init vec, call del at scope exit + c_auto (csset_int, set) // declare and init set, call del at scope exit { cvec_int_push_back(&vec, csptr_int_make(2021)); cvec_int_push_back(&vec, csptr_int_make(2012)); @@ -110,7 +110,7 @@ int main() printf("\nset:"); c_foreach (i, csset_int, set) printf(" %d", *i.ref->get); - c_forvar (csptr_int p = csptr_int_clone(vec.data[0]), csptr_int_del(&p)) { + c_autovar (csptr_int p = csptr_int_clone(vec.data[0]), csptr_int_del(&p)) { printf("\n%d is now owned by %zu objects\n", *p.get, *p.use_count); } diff --git a/docs/csview_api.md b/docs/csview_api.md index 905a6489..6125ef07 100644 --- a/docs/csview_api.md +++ b/docs/csview_api.md @@ -166,7 +166,7 @@ int main() print_split(c_sv("This has no matching separator"), c_sv("xx")); puts(""); - c_forvar (cvec_str v = string_split(c_sv("Split,this,,string,now,"), c_sv(",")), cvec_str_del(&v)) + c_autovar (cvec_str v = string_split(c_sv("Split,this,,string,now,"), c_sv(",")), cvec_str_del(&v)) c_foreach (i, cvec_str, v) printf("\"%s\"\n", i.ref->str); } diff --git a/examples/advanced.c b/examples/advanced.c index e4d3411e..9ec73aa7 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -47,7 +47,7 @@ static inline VikingRaw viking_toRaw(const Viking* vk) { int main() { - c_forvar (cmap_vk vikings = cmap_vk_init(), cmap_vk_del(&vikings)) { + c_autovar (cmap_vk vikings = cmap_vk_init(), cmap_vk_del(&vikings)) { c_emplace(cmap_vk, vikings, { { {"Einar", "Norway"}, 20}, { {"Olaf", "Denmark"}, 24}, diff --git a/examples/astar.c b/examples/astar.c index 5571c306..5316b954 100644 --- a/examples/astar.c +++ b/examples/astar.c @@ -81,9 +81,9 @@ astar(cstr* maze, int width) {
cdeq_point path = cdeq_point_init();
- c_forauto (cpque_point, front)
- c_forauto (csmap_pstep, from)
- c_forauto (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);
@@ -132,7 +132,7 @@ astar(cstr* maze, int width) int
main(void)
{
- c_forvar (cstr maze = cstr_lit(
+ c_autovar (cstr maze = cstr_lit(
"#########################################################################\n"
"# # # # # # #\n"
"# # ######### # ##### ######### ##### ##### ##### # ! #\n"
@@ -158,7 +158,7 @@ main(void) "#########################################################################\n"), cstr_del(&maze))
{
int width = cstr_find(maze, "\n") + 1;
- c_forvar (cdeq_point path = astar(&maze, width), cdeq_point_del(&path))
+ c_autovar (cdeq_point path = astar(&maze, width), cdeq_point_del(&path))
{
c_foreach (it, cdeq_point, path) maze.str[point_index(it.ref)] = 'x';
printf("%s", maze.str);
diff --git a/examples/birthday.c b/examples/birthday.c index 90b57066..242ce78a 100644 --- a/examples/birthday.c +++ b/examples/birthday.c @@ -18,7 +18,7 @@ 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_init(seed);
- c_forauto (cmap_ic, m)
+ c_auto (cmap_ic, m)
{
cmap_ic_reserve(&m, N);
c_forrange (i, N) {
@@ -41,7 +41,7 @@ void test_distribution(void) stc64_t rng = stc64_init(seed);
const size_t N = 1ull << BITS ;
- c_forauto (cmap_x, map) {
+ c_auto (cmap_x, map) {
c_forrange (N) {
uint64_t k = stc64_rand(&rng);
cmap_x_emplace(&map, k & 0xf, 0).ref->second += 1;
diff --git a/examples/bits.c b/examples/bits.c index d8c6f762..9263f88c 100644 --- a/examples/bits.c +++ b/examples/bits.c @@ -3,7 +3,7 @@ int main()
{
- c_forvar (cbits set = cbits_with_size(23, true), cbits_del(&set)) {
+ c_autovar (cbits set = cbits_with_size(23, true), cbits_del(&set)) {
printf("count %zu, %zu\n", cbits_count(set), set.size);
cbits s1 = cbits_from_str("1110100110111");
char buf[256];
@@ -13,7 +13,7 @@ int main() cbits_reset(&set, 9);
cbits_resize(&set, 43, false);
- c_forbuffer (str, char, set.size + 1)
+ c_autobuf (str, char, set.size + 1)
printf(" str: %s\n", cbits_to_str(set, str, 0, -1));
printf("%4zu: ", set.size);
@@ -36,7 +36,7 @@ int main() printf("%d", cbits_test(set, i));
puts("");
- c_forvar (cbits s2 = cbits_clone(set), cbits_del(&s2)) {
+ c_autovar (cbits s2 = cbits_clone(set), cbits_del(&s2)) {
cbits_flip_all(&s2);
cbits_set(&s2, 16);
cbits_set(&s2, 17);
diff --git a/examples/cpque.c b/examples/cpque.c index 0e21a5f7..15bc2daa 100644 --- a/examples/cpque.c +++ b/examples/cpque.c @@ -36,9 +36,9 @@ int main() {
const int data[] = {1,8,5,6,3,4,0,9,7,2};
- c_forauto (cpque_imax, q) // init() and defered del()
- c_forauto (cpque_imin, q2)
- c_forauto (cpque_imix, q3)
+ c_auto (cpque_imax, q) // init() and defered del()
+ c_auto (cpque_imin, q2)
+ c_auto (cpque_imix, q3)
{
c_forrange (n, c_arraylen(data))
cpque_imax_push(&q, n);
diff --git a/examples/csmap_erase.c b/examples/csmap_erase.c index 619efb31..c8ecb5b1 100644 --- a/examples/csmap_erase.c +++ b/examples/csmap_erase.c @@ -17,7 +17,7 @@ void printmap(csmap_my map) int main() { - c_forauto (csmap_my, m1) + c_auto (csmap_my, m1) { // Fill in some data to test with, one at a time csmap_my_insert(&m1, 1, cstr_lit("A")); @@ -34,7 +34,7 @@ int main() printmap(m1); } - c_forauto (csmap_my, m2) + c_auto (csmap_my, m2) { // Fill in some data to test with, one at a time, using c_emplace() c_emplace(csmap_my, m2, { @@ -56,7 +56,7 @@ int main() printmap(m2); } - c_forauto (csmap_my, m3) + c_auto (csmap_my, m3) { // Fill in some data to test with, one at a time, using emplace csmap_my_emplace(&m3, 1, "red"); diff --git a/examples/csmap_find.c b/examples/csmap_find.c index 30c7a685..55f7c23f 100644 --- a/examples/csmap_find.c +++ b/examples/csmap_find.c @@ -43,8 +43,8 @@ void findit(csmap_istr c, csmap_istr_key_t val) int main() { - c_forauto (csmap_istr, m1) - c_forauto (cvec_istr, v) + c_auto (csmap_istr, m1) + c_auto (cvec_istr, v) { c_emplace(csmap_istr, m1, { { 40, "Zr" }, { 45, "Rh" } }); puts("The starting map m1 is (key, value):"); diff --git a/examples/csmap_insert.c b/examples/csmap_insert.c index 25f7a23f..1bb47697 100644 --- a/examples/csmap_insert.c +++ b/examples/csmap_insert.c @@ -34,7 +34,7 @@ void print_istr(csmap_istr map) { int main()
{
// insert single values
- c_forauto (csmap_ii, m1) {
+ c_auto (csmap_ii, m1) {
csmap_ii_insert(&m1, 1, 10);
csmap_ii_insert(&m1, 2, 20);
@@ -61,8 +61,8 @@ int main() }
// The templatized version inserting a jumbled range
- c_forauto (csmap_ii, m2)
- c_forauto (cvec_ii, v) {
+ c_auto (csmap_ii, m2)
+ c_auto (cvec_ii, v) {
typedef cvec_ii_value_t ipair;
cvec_ii_push_back(&v, (ipair){43, 294});
cvec_ii_push_back(&v, (ipair){41, 262});
@@ -82,7 +82,7 @@ int main() }
// The templatized versions move-constructing elements
- c_forauto (csmap_istr, m3) {
+ c_auto (csmap_istr, m3) {
csmap_istr_value_t ip1 = {475, cstr_lit("blue")}, ip2 = {510, cstr_lit("green")};
// single element
@@ -97,7 +97,7 @@ int main() puts("");
}
- c_forauto (csmap_ii, m4) {
+ c_auto (csmap_ii, m4) {
// Insert the elements from an initializer_list
c_emplace(csmap_ii, m4, { { 4, 44 }, { 2, 22 }, { 3, 33 }, { 1, 11 }, { 5, 55 } });
puts("After initializer_list insertion, m4 contains:");
diff --git a/examples/csset_erase.c b/examples/csset_erase.c index a8b2c9d0..c32bf70c 100644 --- a/examples/csset_erase.c +++ b/examples/csset_erase.c @@ -5,7 +5,7 @@ int main()
{
- c_forauto (csset_int, set)
+ c_auto (csset_int, set)
{
c_emplace(csset_int, set, {30, 20, 80, 40, 60, 90, 10, 70, 50});
c_foreach (k, csset_int, set)
diff --git a/examples/cstr_match.c b/examples/cstr_match.c index bb3a63fe..28c1a22b 100644 --- a/examples/cstr_match.c +++ b/examples/cstr_match.c @@ -3,7 +3,7 @@ int main()
{
- c_forvar (cstr ss = cstr_lit("The quick brown fox jumps over the lazy dog.JPG"), cstr_del(&ss)) {
+ c_autovar (cstr ss = cstr_lit("The quick brown fox jumps over the lazy dog.JPG"), cstr_del(&ss)) {
size_t pos = cstr_find_n(ss, "brown", 0, 5);
printf("%zu [%s]\n", pos, pos == cstr_npos ? "<NULL>" : &ss.str[pos]);
printf("equals: %d\n", cstr_equalto(ss, "The quick brown fox jumps over the lazy dog.JPG"));
diff --git a/examples/demos.c b/examples/demos.c index 03bba7a8..a874d38d 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -3,7 +3,7 @@ void stringdemo1()
{
printf("\nSTRINGDEMO1\n");
- c_forvar (cstr cs = cstr_from("one-nine-three-seven-five"), cstr_del(&cs))
+ c_autovar (cstr cs = cstr_from("one-nine-three-seven-five"), cstr_del(&cs))
{
printf("%s.\n", cs.str);
@@ -35,7 +35,7 @@ void stringdemo1() void vectordemo1()
{
printf("\nVECTORDEMO1\n");
- c_forvar (cvec_ix bignums = cvec_ix_with_capacity(100), cvec_ix_del(&bignums))
+ c_autovar (cvec_ix bignums = cvec_ix_with_capacity(100), cvec_ix_del(&bignums))
{
cvec_ix_reserve(&bignums, 100);
for (size_t i = 10; i <= 100; i += 10)
@@ -59,7 +59,7 @@ void vectordemo1() void vectordemo2()
{
printf("\nVECTORDEMO2\n");
- c_forvar (cvec_str names = cvec_str_init(), cvec_str_del(&names)) {
+ c_autovar (cvec_str names = cvec_str_init(), cvec_str_del(&names)) {
cvec_str_emplace_back(&names, "Mary");
cvec_str_emplace_back(&names, "Joe");
cvec_str_emplace_back(&names, "Chris");
@@ -79,8 +79,8 @@ void vectordemo2() void listdemo1()
{
printf("\nLISTDEMO1\n");
- c_forvar (clist_ix nums = clist_ix_init(), clist_ix_del(&nums))
- c_forvar (clist_ix nums2 = clist_ix_init(), clist_ix_del(&nums2))
+ c_autovar (clist_ix nums = clist_ix_init(), clist_ix_del(&nums))
+ c_autovar (clist_ix nums2 = clist_ix_init(), clist_ix_del(&nums2))
{
for (int i = 0; i < 10; ++i)
clist_ix_push_back(&nums, i);
@@ -145,7 +145,7 @@ void mapdemo1() void mapdemo2()
{
printf("\nMAPDEMO2\n");
- c_forvar (cmap_si nums = cmap_si_init(), cmap_si_del(&nums))
+ c_autovar (cmap_si nums = cmap_si_init(), cmap_si_del(&nums))
{
cmap_si_emplace_or_assign(&nums, "Hello", 64);
cmap_si_emplace_or_assign(&nums, "Groovy", 121);
@@ -193,7 +193,7 @@ void mapdemo3() void arraydemo1()
{
printf("\nARRAYDEMO1\n");
- c_forvar (carr3_f arr3 = carr3_f_with_values(30, 20, 10, 0.0f),
+ c_autovar (carr3_f arr3 = carr3_f_with_values(30, 20, 10, 0.0f),
carr3_f_del(&arr3))
{
arr3.data[5][4][3] = 10.2f;
diff --git a/examples/ex_gauss1.c b/examples/ex_gauss1.c index e345ddd1..42337d3b 100644 --- a/examples/ex_gauss1.c +++ b/examples/ex_gauss1.c @@ -34,8 +34,8 @@ int main() stc64_normalf_t dist = stc64_normalf_init(Mean, StdDev);
// Create and init histogram vec and map with defered destructors:
- c_forauto (cvec_pair, histvec)
- c_forauto (cmap_ii, histmap)
+ c_auto (cvec_pair, histvec)
+ c_auto (cmap_ii, histmap)
{
c_forrange (N) {
int index = (int) round( stc64_normalf(&rng, &dist) );
@@ -49,7 +49,7 @@ int main() cvec_pair_sort(&histvec);
// Print the gaussian bar chart
- c_forauto (cstr, bar)
+ c_auto (cstr, bar)
c_foreach (i, cvec_pair, histvec) {
size_t n = (size_t) (i.ref->second * StdDev * Scale * 2.5 / (float)N);
if (n > 0) {
diff --git a/examples/ex_gauss2.c b/examples/ex_gauss2.c index 850cd2de..a57251bc 100644 --- a/examples/ex_gauss2.c +++ b/examples/ex_gauss2.c @@ -21,8 +21,8 @@ int main() stc64_normalf_t dist = stc64_normalf_init(Mean, StdDev);
// Create and init histogram map with defered destruct
- c_forauto (csmap_int, mhist)
- c_forauto (cstr, bar)
+ c_auto (csmap_int, mhist)
+ c_auto (cstr, bar)
{
c_forrange (N) {
int index = (int) round( stc64_normalf(&rng, &dist) );
diff --git a/examples/inits.c b/examples/inits.c index 04860258..64d1e970 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -35,7 +35,7 @@ int main(void) {
// CVEC FLOAT / PRIORITY QUEUE
- c_forauto (cpque_f, floats) {
+ c_auto (cpque_f, floats) {
float nums[] = {4.0f, 2.0f, 5.0f, 3.0f, 1.0f};
c_forrange (i, c_arraylen(nums)) {
@@ -60,7 +60,7 @@ int main(void) // CMAP ID
int year = 2020;
- c_forauto (cmap_id, idnames) {
+ c_auto (cmap_id, idnames) {
cmap_id_emplace(&idnames, 100, "Hello");
cmap_id_insert(&idnames, 110, cstr_from("World"));
cmap_id_insert(&idnames, 120, cstr_from_fmt("Howdy, -%d-", year));
@@ -72,7 +72,7 @@ int main(void) // CMAP CNT
- c_forauto (cmap_cnt, countries) {
+ c_auto (cmap_cnt, countries) {
c_emplace(cmap_cnt, countries, {
{"Norway", 100},
{"Denmark", 50},
@@ -95,7 +95,7 @@ int main(void) // CVEC PAIR
- c_forauto (cvec_ip, pairs1) {
+ c_auto (cvec_ip, pairs1) {
c_emplace (cvec_ip, pairs1, {{5, 6}, {3, 4}, {1, 2}, {7, 8}});
cvec_ip_sort(&pairs1);
@@ -106,7 +106,7 @@ int main(void) // CLIST PAIR
- c_forauto (clist_ip, pairs2) {
+ c_auto (clist_ip, pairs2) {
c_emplace(clist_ip, pairs2, {{5, 6}, {3, 4}, {1, 2}, {7, 8}});
clist_ip_sort(&pairs2);
diff --git a/examples/list.c b/examples/list.c index f08ba34d..ab5c70e2 100644 --- a/examples/list.c +++ b/examples/list.c @@ -10,7 +10,7 @@ int main() { int k;
const int n = 2000000;
- c_forauto (clist_fx, list)
+ c_auto (clist_fx, list)
{
stc64_t rng = stc64_init(1234);
stc64_uniformf_t dist = stc64_uniformf_init(100.0f, n);
diff --git a/examples/list_erase.c b/examples/list_erase.c index 6d619b9d..9a3df2f6 100644 --- a/examples/list_erase.c +++ b/examples/list_erase.c @@ -7,7 +7,7 @@ int main ()
{
- c_forvar (clist_i L = clist_i_init(), clist_i_del(&L))
+ c_autovar (clist_i L = clist_i_init(), clist_i_del(&L))
{
c_emplace(clist_i, L, {10, 20, 30, 40, 50});
// 10 20 30 40 50
diff --git a/examples/list_splice.c b/examples/list_splice.c index e9139156..997c1cc3 100644 --- a/examples/list_splice.c +++ b/examples/list_splice.c @@ -15,7 +15,7 @@ void print_ilist(const char* s, clist_i list) int main () { - c_forauto (clist_i, list1, list2) + c_auto (clist_i, list1, list2) { c_emplace(clist_i, list1, {1, 2, 3, 4, 5}); c_emplace(clist_i, list2, {10, 20, 30, 40, 50}); diff --git a/examples/mapmap.c b/examples/mapmap.c index b158b96a..d24c4748 100644 --- a/examples/mapmap.c +++ b/examples/mapmap.c @@ -16,7 +16,7 @@ int main(void)
{
- c_forauto (cmap_cfg, cfg)
+ c_auto (cmap_cfg, cfg)
{
cmap_cfg_insert(&cfg, cstr_from("user"), cmap_str_init());
cmap_cfg_insert(&cfg, cstr_from("group"), cmap_str_init());
diff --git a/examples/mmap.c b/examples/mmap.c index 1cf145d6..ad2e28c8 100644 --- a/examples/mmap.c +++ b/examples/mmap.c @@ -30,7 +30,7 @@ void insert(csmap_mult* mmap, int key, const char* str) int main()
{
- c_forauto (csmap_mult, mmap)
+ c_auto (csmap_mult, mmap)
{
// list-initialize
struct {int i; const char* s;} vals[] = {{2, "foo"}, {2, "bar"}, {3, "baz"}, {1, "abc"}, {5, "def"}};
diff --git a/examples/multimap.c b/examples/multimap.c index 0f5ce538..64e3493b 100644 --- a/examples/multimap.c +++ b/examples/multimap.c @@ -59,7 +59,7 @@ void OlympicLocation_del(OlympicLocation* self) { int main()
{
// Define the multimap with destructor defered to when block is completed.
- c_forauto (csmap_OL, multimap)
+ c_auto (csmap_OL, multimap)
{
const clist_OL empty = clist_OL_init();
diff --git a/examples/phonebook.c b/examples/phonebook.c index a0aee757..b7d3faba 100644 --- a/examples/phonebook.c +++ b/examples/phonebook.c @@ -41,14 +41,14 @@ int main(int argc, char **argv) {
c_static_assert(sizeof argc == 4);
- c_forauto (cset_str, names) {
+ c_auto (cset_str, names) {
c_emplace (cset_str, names, {"Hello", "Cool", "True"});
c_foreach (i, cset_str, names) printf("%s ", i.ref->str);
puts("");
}
bool erased;
- c_forauto (cmap_str, phone_book) {
+ c_auto (cmap_str, phone_book) {
c_emplace (cmap_str, phone_book, {
{"Lilia Friedman", "(892) 670-4739"},
{"Tariq Beltran", "(489) 600-7575"},
diff --git a/examples/prime.c b/examples/prime.c index c0e61002..f858831a 100644 --- a/examples/prime.c +++ b/examples/prime.c @@ -27,7 +27,7 @@ int main(void) printf("computing prime numbers up to %zu\n", n);
clock_t t1 = clock();
- c_forvar (cbits primes = sieveOfEratosthenes(n + 1), cbits_del(&primes)) {
+ c_autovar (cbits primes = sieveOfEratosthenes(n + 1), cbits_del(&primes)) {
puts("done");
size_t np = cbits_count(primes);
clock_t t2 = clock();
diff --git a/examples/priority.c b/examples/priority.c index 09ede43c..8ca02409 100644 --- a/examples/priority.c +++ b/examples/priority.c @@ -12,7 +12,7 @@ int main() { size_t N = 10000000;
stc64_t rng = stc64_init(time(NULL));
stc64_uniform_t dist = stc64_uniform_init(0, N * 10);
- c_forauto (cpque_i, heap)
+ c_auto (cpque_i, heap)
{
// Push ten million random numbers to priority queue
printf("Push %zu numbers\n", N);
diff --git a/examples/queue.c b/examples/queue.c index dabb0a08..602e9f0f 100644 --- a/examples/queue.c +++ b/examples/queue.c @@ -11,7 +11,7 @@ int main() { stc64_t rng = stc64_init(1234);
dist = stc64_uniform_init(0, n);
- c_forauto (cqueue_i, queue)
+ c_auto (cqueue_i, queue)
{
// Push ten million random numbers onto the queue.
c_forrange (n)
diff --git a/examples/read.c b/examples/read.c index 2e8320eb..c415c6e5 100644 --- a/examples/read.c +++ b/examples/read.c @@ -7,8 +7,8 @@ cvec_str read_file(const char* name)
{
cvec_str vec = cvec_str_init();
- c_forvar (FILE* f = fopen(name, "r"), fclose(f))
- c_forauto (cstr, line)
+ c_autovar (FILE* f = fopen(name, "r"), fclose(f))
+ c_auto (cstr, line)
while (cstr_getline(&line, f))
cvec_str_emplace_back(&vec, line.str);
return vec;
@@ -17,7 +17,7 @@ cvec_str read_file(const char* name) int main()
{
int n = 0;
- c_forvar (cvec_str vec = read_file(__FILE__), cvec_str_del(&vec))
+ c_autovar (cvec_str vec = read_file(__FILE__), cvec_str_del(&vec))
c_foreach (i, cvec_str, vec)
printf("%5d: %s\n", ++n, i.ref->str);
diff --git a/examples/replace.c b/examples/replace.c index cfbcc1e5..9e658922 100644 --- a/examples/replace.c +++ b/examples/replace.c @@ -13,7 +13,7 @@ int main () // Ustring positions: 0123456789*123456789*12345
cstr s = cstr_from(base); // "this is a test string."
cstr m = cstr_clone(s);
- c_fordefer (cstr_del(&s), cstr_del(&m)) {
+ c_autoscope (0, cstr_del(&s), cstr_del(&m)) {
cstr_append(&m, m.str);
cstr_append(&m, m.str);
printf("%s\n", m.str);
diff --git a/examples/sharedptr.c b/examples/sharedptr.c index a45e19bc..4d28e1c1 100644 --- a/examples/sharedptr.c +++ b/examples/sharedptr.c @@ -16,8 +16,8 @@ void int_del(int* x) { int main()
{
- c_forauto (cvec_int, vec) // declare and init vec, call del at scope exit
- c_forauto (csset_int, set) // declare and init set, call del at scope exit
+ c_auto (cvec_int, vec) // declare and init vec, call del at scope exit
+ c_auto (csset_int, set) // declare and init set, call del at scope exit
{
cvec_int_push_back(&vec, csptr_int_make(2021));
cvec_int_push_back(&vec, csptr_int_make(2012));
@@ -43,7 +43,7 @@ int main() printf("\nset:");
c_foreach (i, csset_int, set) printf(" %d", *i.ref->get);
- c_forvar (csptr_int p = csptr_int_clone(vec.data[0]), csptr_int_del(&p)) {
+ c_autovar (csptr_int p = csptr_int_clone(vec.data[0]), csptr_int_del(&p)) {
printf("\n%d is now owned by %zu objects\n", *p.get, *p.use_count);
}
diff --git a/examples/splitstr.c b/examples/splitstr.c index 42dd4dbd..e4f6ab8a 100644 --- a/examples/splitstr.c +++ b/examples/splitstr.c @@ -36,7 +36,7 @@ int main() cstr string = cstr_lit("Split,this,,string,now,");
cvec_str vec = string_split(cstr_sv(string), c_sv(","));
- c_fordefer (cvec_str_del(&vec), cstr_del(&string))
+ c_autoscope (0, cvec_str_del(&vec), cstr_del(&string))
c_foreach (i, cvec_str, vec)
printf("\t\"%s\"\n", i.ref->str);
}
\ No newline at end of file diff --git a/examples/stack.c b/examples/stack.c index 89987b7b..7da3063a 100644 --- a/examples/stack.c +++ b/examples/stack.c @@ -13,7 +13,7 @@ int main() {
cstack_i stack = cstack_i_init();
cstack_c chars = cstack_c_init();
- c_fordefer (cstack_i_del(&stack), cstack_c_del(&chars))
+ c_autoscope (0, cstack_i_del(&stack), cstack_c_del(&chars))
{
c_forrange (i, int, 101)
cstack_i_push(&stack, i*i);
diff --git a/examples/words.c b/examples/words.c index 442f04f0..7ab6d026 100644 --- a/examples/words.c +++ b/examples/words.c @@ -11,8 +11,8 @@ int main1() { - c_forauto (cvec_str, words) - c_forauto (cmap_strn, word_map) + c_auto (cvec_str, words) + c_auto (cmap_strn, word_map) { c_emplace (cvec_str, words, { "this", "sentence", "is", "not", "a", "sentence", diff --git a/include/stc/carr2.h b/include/stc/carr2.h index e390469e..93cabb6e 100644 --- a/include/stc/carr2.h +++ b/include/stc/carr2.h @@ -34,7 +34,7 @@ int main() { int w = 7, h = 5; - c_forvar (carr2_int image = carr2_int_init(w, h), carr2_int_del(&image)) + c_autovar (carr2_int image = carr2_int_init(w, h), carr2_int_del(&image)) { int *dat = carr2_int_data(&image); for (int i = 0; i < carr2_int_size(image); ++i) diff --git a/include/stc/carr3.h b/include/stc/carr3.h index 8467739d..8ba67d43 100644 --- a/include/stc/carr3.h +++ b/include/stc/carr3.h @@ -34,7 +34,7 @@ int main() { int w = 7, h = 5, d = 3; - c_forvar (carr3_int image = carr3_int_init(w, h, d), carr3_int_del(&image)) + c_autovar (carr3_int image = carr3_int_init(w, h, d), carr3_int_del(&image)) { int *dat = carr3_int_data(&image); for (int i = 0; i < carr3_int_size(image); ++i) diff --git a/include/stc/cbits.h b/include/stc/cbits.h index af767207..9bf28d44 100644 --- a/include/stc/cbits.h +++ b/include/stc/cbits.h @@ -30,7 +30,7 @@ Similar to boost::dynamic_bitset / std::bitset #include "cbits.h"
int main() {
- c_forvar (cbits bset = cbits_with_size(23, true), cbits_del(&bset))
+ c_autovar (cbits bset = cbits_with_size(23, true), cbits_del(&bset))
{
cbits_reset(&bset, 9);
cbits_resize(&bset, 43, false);
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index d11f1b3f..a97828af 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -136,22 +136,22 @@ STC_API uint64_t c_default_hash(const void *key, size_t len); for (type i=start, _c_inc=step, _c_end=(stop) - (0 < _c_inc) \
; (i <= _c_end) == (0 < _c_inc); i += _c_inc)
-#define c_forvar(declvar, ...) for (declvar, *_c_ii = NULL; !_c_ii; ++_c_ii, __VA_ARGS__)
-#define c_forscope(start, end) for (int _c_ii = (start, 0); !_c_ii; ++_c_ii, end)
-#define c_fordefer(...) for (int _c_ii = 0; !_c_ii; ++_c_ii, __VA_ARGS__)
-
-#define c_forauto(...) c_MACRO_OVERLOAD(c_forauto, __VA_ARGS__)
-#define c_forauto_2(CX, a) \
- c_forvar(CX a = CX##_init(), CX##_del(&a))
-#define c_forauto_3(CX, a, b) \
- c_forvar(c_EXPAND(CX a = CX##_init(), b = CX##_init()), \
- CX##_del(&b), CX##_del(&a))
-#define c_forauto_4(CX, a, b, c) \
- c_forvar(c_EXPAND(CX a = CX##_init(), b = CX##_init(), c = CX##_init()), \
- CX##_del(&c), CX##_del(&b), CX##_del(&a))
-
-#define c_forbuffer(b, type, n) c_forbuffer_N(b, type, n, 256)
-#define c_forbuffer_N(b, type, n, BYTES) \
+#define c_autoscope(init, ...) for (int _c_ii = (init, 0); !_c_ii; ++_c_ii, __VA_ARGS__)
+#define c_autovar(declvar, ...) for (declvar, *_c_ii = NULL; !_c_ii; ++_c_ii, __VA_ARGS__)
+#define c_exitauto continue
+
+#define c_auto(...) c_MACRO_OVERLOAD(c_auto, __VA_ARGS__)
+#define c_auto_2(CX, a) \
+ c_autovar(CX a = CX##_init(), CX##_del(&a))
+#define c_auto_3(CX, a, b) \
+ c_autovar(c_EXPAND(CX a = CX##_init(), b = CX##_init()), \
+ CX##_del(&b), CX##_del(&a))
+#define c_auto_4(CX, a, b, c) \
+ c_autovar(c_EXPAND(CX a = CX##_init(), b = CX##_init(), c = CX##_init()), \
+ CX##_del(&c), CX##_del(&b), CX##_del(&a))
+
+#define c_autobuf(b, type, n) c_autobuf_N(b, type, n, 256)
+#define c_autobuf_N(b, type, n, BYTES) \
for (type _c_b[((BYTES) - 1) / sizeof(type) + 1], \
*b = (n)*sizeof *b > (BYTES) ? c_new_n(type, n) : _c_b \
; b; b != _c_b ? c_free(b) : (void)0, b = NULL)
diff --git a/include/stc/clist.h b/include/stc/clist.h index 83e08c24..0b5cd35c 100644 --- a/include/stc/clist.h +++ b/include/stc/clist.h @@ -35,7 +35,7 @@ #include <stc/clist.h>
int main() {
- c_forvar (clist_ix list = clist_ix_init(), clist_ix_del(&list))
+ c_autovar (clist_ix list = clist_ix_init(), clist_ix_del(&list))
{
stc64_t rng = stc64_init(12345);
int n;
diff --git a/include/stc/cmap.h b/include/stc/cmap.h index 989335c1..096a7045 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -31,7 +31,7 @@ #include <stc/cmap.h>
int main(void) {
- c_forvar (cmap_ichar m = cmap_ichar_init(), cmap_ichar_del(&m))
+ c_autovar (cmap_ichar m = cmap_ichar_init(), cmap_ichar_del(&m))
{
cmap_ichar_emplace(&m, 5, 'a');
cmap_ichar_emplace(&m, 8, 'b');
diff --git a/include/stc/cqueue.h b/include/stc/cqueue.h index f1d173e2..45e3c2a6 100644 --- a/include/stc/cqueue.h +++ b/include/stc/cqueue.h @@ -33,7 +33,7 @@ int main() { stc64_t rng = stc64_init(1234);
stc64_uniform_t dist = stc64_uniform_init(0, n);
- c_forauto (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/csmap.h b/include/stc/csmap.h index d52f70c4..cc7eeb49 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -32,7 +32,7 @@ #include <stc/csmap.h>
int main(void) {
- c_forvar (csmap_sx m = csmap_sx_init(), csmap_sx_del(&m))
+ c_autovar (csmap_sx m = csmap_sx_init(), csmap_sx_del(&m))
{
csmap_sx_emplace(&m, "Testing one", 1.234);
csmap_sx_emplace(&m, "Testing two", 12.34);
diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 681f38b1..23830d75 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -292,7 +292,7 @@ STC_DEF void cstr_replace_n(cstr* self, size_t pos, size_t len, const char* str, size_t n) {
size_t sz = cstr_size(*self);
if (len > sz - pos) len = sz - pos;
- c_forbuffer (xstr, char, n) {
+ c_autobuf (xstr, char, n) {
memcpy(xstr, str, n);
_cstr_internal_move(self, pos + len, pos + n);
memcpy(&self->str[pos], xstr, n);
diff --git a/tests/test_new_arr.c b/tests/test_new_arr.c index 54423349..fef2ab01 100644 --- a/tests/test_new_arr.c +++ b/tests/test_new_arr.c @@ -10,7 +10,7 @@ int main() { int w = 7, h = 5, d = 3; - c_forvar (carr2_int image = carr2_int_init(w, h), carr2_int_del(&image)) + c_autovar (carr2_int image = carr2_int_init(w, h), carr2_int_del(&image)) { int *dat = carr2_int_data(&image); for (size_t i = 0; i < carr2_int_size(image); ++i) @@ -26,7 +26,7 @@ int main() } puts("\n"); - c_forvar (carr3_int image = carr3_int_init(w, h, d), carr3_int_del(&image)) + c_autovar (carr3_int image = carr3_int_init(w, h, d), carr3_int_del(&image)) { int *dat = carr3_int_data(&image); for (size_t i = 0; i < carr3_int_size(image); ++i) diff --git a/tests/test_new_queue.c b/tests/test_new_queue.c index a76f4fde..a7fdb723 100644 --- a/tests/test_new_queue.c +++ b/tests/test_new_queue.c @@ -23,7 +23,7 @@ int main() { stc64_t rng = stc64_init(time(NULL));
stc64_uniform_t dist = stc64_uniform_init(0, n);
- c_forauto (cqueue_int, Q)
+ c_auto (cqueue_int, Q)
{
// Push eight million random numbers onto the queue.
for (int i=0; i<n; ++i)
diff --git a/tests/test_new_smap.c b/tests/test_new_smap.c index 033749ce..c05d90b9 100644 --- a/tests/test_new_smap.c +++ b/tests/test_new_smap.c @@ -39,10 +39,10 @@ int point_compare(const Point* a, const Point* b) { int main()
{
- c_forauto (csmap_int, map)
+ c_auto (csmap_int, map)
csmap_int_insert(&map, 123, 321);
- c_forauto (csmap_pnt, pmap) {
+ c_auto (csmap_pnt, pmap) {
csmap_pnt_insert(&pmap, (Point){42, 14}, 1);
csmap_pnt_insert(&pmap, (Point){32, 94}, 2);
csmap_pnt_insert(&pmap, (Point){62, 81}, 3);
@@ -51,7 +51,7 @@ int main() puts("");
}
- c_forauto (csmap_str, smap) {
+ c_auto (csmap_str, smap) {
csmap_str_emplace(&smap, "Hello, friend", "this is the mapped value");
csmap_str_emplace(&smap, "The brown fox", "jumped");
csmap_str_emplace(&smap, "This is the time", "for all good things");
@@ -59,7 +59,7 @@ int main() printf(" (%s: %s)\n", i.ref->first.str, i.ref->second.str);
}
- c_forauto (csset_str, sset) {
+ c_auto (csset_str, sset) {
csset_str_emplace(&sset, "Hello, friend");
csset_str_emplace(&sset, "Goodbye, foe");
printf("Found? %s\n", csset_str_contains(&sset, "Hello, friend") ? "true" : "false");
diff --git a/tests/test_new_sptr.c b/tests/test_new_sptr.c index 2ef31790..186f6e7b 100644 --- a/tests/test_new_sptr.c +++ b/tests/test_new_sptr.c @@ -28,12 +28,12 @@ void Person_del(Person* p) { #include <stc/csset.h>
int main(void) {
- c_forvar (csptr_person p = csptr_person_make(Person_init("John", "Smiths")), csptr_person_del(&p))
- c_forvar (csptr_person q = csptr_person_clone(p), csptr_person_del(&q)) // share the pointer
+ c_autovar (csptr_person p = csptr_person_make(Person_init("John", "Smiths")), csptr_person_del(&p))
+ c_autovar (csptr_person q = csptr_person_clone(p), csptr_person_del(&q)) // share the pointer
{
printf("%s %s. uses: %zu\n", q.get->name.str, q.get->last.str, *q.use_count);
- c_forauto (csset_iptr, map) {
+ c_auto (csset_iptr, map) {
csset_iptr_insert(&map, csptr_int_make(2021));
csset_iptr_insert(&map, csptr_int_make(2033));
|
