summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Lovset <[email protected]>2021-09-20 10:36:25 +0200
committerTyge Lovset <[email protected]>2021-09-20 10:36:25 +0200
commit0861391b9b3b8ad37e24b0dba7da192f31e48a6b (patch)
treedf78821e47690e1793465d0fcf3d068ad33ccf44 /examples
parent625a0fad0c1d187d56d3a9c9bb831987e9250e86 (diff)
downloadSTC-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
Diffstat (limited to 'examples')
-rw-r--r--examples/advanced.c2
-rw-r--r--examples/astar.c10
-rw-r--r--examples/birthday.c4
-rw-r--r--examples/bits.c6
-rw-r--r--examples/cpque.c6
-rw-r--r--examples/csmap_erase.c6
-rw-r--r--examples/csmap_find.c4
-rw-r--r--examples/csmap_insert.c10
-rw-r--r--examples/csset_erase.c2
-rw-r--r--examples/cstr_match.c2
-rw-r--r--examples/demos.c14
-rw-r--r--examples/ex_gauss1.c6
-rw-r--r--examples/ex_gauss2.c4
-rw-r--r--examples/inits.c10
-rw-r--r--examples/list.c2
-rw-r--r--examples/list_erase.c2
-rw-r--r--examples/list_splice.c2
-rw-r--r--examples/mapmap.c2
-rw-r--r--examples/mmap.c2
-rw-r--r--examples/multimap.c2
-rw-r--r--examples/phonebook.c4
-rw-r--r--examples/prime.c2
-rw-r--r--examples/priority.c2
-rw-r--r--examples/queue.c2
-rw-r--r--examples/read.c6
-rw-r--r--examples/replace.c2
-rw-r--r--examples/sharedptr.c6
-rw-r--r--examples/splitstr.c2
-rw-r--r--examples/stack.c2
-rw-r--r--examples/words.c4
30 files changed, 65 insertions, 65 deletions
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",