diff options
| author | Tyge Løvset <[email protected]> | 2021-05-24 12:43:39 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-05-24 12:43:39 +0200 |
| commit | 64f50b93b08a8015783b2887e1ab5afd5fedb40c (patch) | |
| tree | ca70f0b4c87b0d59a9689b12d26bfa2bab160916 /examples | |
| parent | 771a8dff31b0c0a905c57ec6f590cd03975f8817 (diff) | |
| download | STC-modified-64f50b93b08a8015783b2887e1ab5afd5fedb40c.tar.gz STC-modified-64f50b93b08a8015783b2887e1ab5afd5fedb40c.zip | |
Renamed c_with => c_fordefer, and removed c_withvar. Macros were too deceiving and hid the fact that it was for-loops. Now it is more explicit.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/advanced.c | 2 | ||||
| -rw-r--r-- | examples/birthday.c | 2 | ||||
| -rw-r--r-- | examples/bits.c | 6 | ||||
| -rw-r--r-- | examples/cpque.c | 6 | ||||
| -rw-r--r-- | examples/csmap_erase.c | 6 | ||||
| -rw-r--r-- | examples/csmap_find.c | 4 | ||||
| -rw-r--r-- | examples/csmap_insert.c | 12 | ||||
| -rw-r--r-- | examples/demos.c | 12 | ||||
| -rw-r--r-- | examples/ex_gauss1.c | 6 | ||||
| -rw-r--r-- | examples/ex_gauss2.c | 4 | ||||
| -rw-r--r-- | examples/inits.c | 10 | ||||
| -rw-r--r-- | examples/list.c | 2 | ||||
| -rw-r--r-- | examples/list_erase.c | 2 | ||||
| -rw-r--r-- | examples/list_splice.c | 7 | ||||
| -rw-r--r-- | examples/mapmap.c | 2 | ||||
| -rw-r--r-- | examples/mmap.c | 2 | ||||
| -rw-r--r-- | examples/multimap.c | 2 | ||||
| -rw-r--r-- | examples/phonebook.c | 4 | ||||
| -rw-r--r-- | examples/prime.c | 2 | ||||
| -rw-r--r-- | examples/priority.c | 2 | ||||
| -rw-r--r-- | examples/queue.c | 2 | ||||
| -rw-r--r-- | examples/replace.c | 2 | ||||
| -rw-r--r-- | examples/stack.c | 2 | ||||
| -rw-r--r-- | examples/stc_astar.c | 6 | ||||
| -rw-r--r-- | examples/svmap.c | 2 | ||||
| -rw-r--r-- | examples/words.c | 4 |
26 files changed, 57 insertions, 56 deletions
diff --git a/examples/advanced.c b/examples/advanced.c index 6d5486ae..1d8a8cf2 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -41,7 +41,7 @@ using_cmap_keydef(vk, Viking, int, vikingraw_equals, vikingraw_hash, int main() { - c_with (cmap_vk vikings = cmap_vk_init(), cmap_vk_del(&vikings)) { + c_fordefer (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/birthday.c b/examples/birthday.c index 18e9cd77..80802572 100644 --- a/examples/birthday.c +++ b/examples/birthday.c @@ -35,7 +35,7 @@ void test_distribution(void) stc64_t rng = stc64_init(seed);
const size_t N = 1ull << BITS ;
- c_with (cmap_x map = cmap_x_init(), cmap_x_del(&map)) {
+ c_fordefer (cmap_x map = cmap_x_init(), cmap_x_del(&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 65be30ac..e478321c 100644 --- a/examples/bits.c +++ b/examples/bits.c @@ -3,7 +3,7 @@ int main()
{
- c_with (cbits set = cbits_with_size(23, true), cbits_del(&set)) {
+ c_fordefer (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];
@@ -12,7 +12,7 @@ int main() cbits_reset(&set, 9);
cbits_resize(&set, 43, false);
- c_withbuf (str, char, set.size + 1)
+ c_forbuffer (str, char, set.size + 1)
printf(" str: %s\n", cbits_to_str(set, str, 0, -1));
printf("%4zu: ", set.size);
@@ -35,7 +35,7 @@ int main() printf("%d", cbits_test(set, i));
puts("");
- c_with (cbits s2 = cbits_clone(set), cbits_del(&s2)) {
+ c_fordefer (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 d43ddef8..937b7ac9 100644 --- a/examples/cpque.c +++ b/examples/cpque.c @@ -31,9 +31,9 @@ int main() {
const int data[] = {1,8,5,6,3,4,0,9,7,2};
- c_withvar (cpque_imax, q) // init() and defered del()
- c_withvar (cpque_imin, q2)
- c_withvar (cpque_imix, q3)
+ c_fordefer (cpque_imax q = cpque_imax_init(), cpque_imax_del(&q)) // init() and defered del()
+ c_fordefer (cpque_imin q2 = cpque_imin_init(), cpque_imin_del(&q2))
+ c_fordefer (cpque_imix q3 = cpque_imix_init(), cpque_imix_del(&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 1276bd7b..58a90d4b 100644 --- a/examples/csmap_erase.c +++ b/examples/csmap_erase.c @@ -15,7 +15,7 @@ void printmap(csmap_my map) int main()
{
- c_with (csmap_my m1 = csmap_my_init(), csmap_my_del(&m1))
+ c_fordefer (csmap_my m1 = csmap_my_init(), csmap_my_del(&m1))
{
// Fill in some data to test with, one at a time
csmap_my_emplace(&m1, 1, "A");
@@ -32,7 +32,7 @@ int main() printmap(m1);
}
- c_withvar (csmap_my, m2)
+ c_fordefer (csmap_my m2 = csmap_my_init(), csmap_my_del(&m2))
{
// Fill in some data to test with, one at a time, using emplace
c_emplace(csmap_my, m2, {
@@ -54,7 +54,7 @@ int main() printmap(m2);
}
- c_withvar (csmap_my, m3)
+ c_fordefer (csmap_my m3 = csmap_my_init(), csmap_my_del(&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 d32cd1b5..4fcedb43 100644 --- a/examples/csmap_find.c +++ b/examples/csmap_find.c @@ -38,8 +38,8 @@ void findit(csmap_istr c, csmap_istr_key_t val) { int main()
{
- c_withvar (csmap_istr, m1)
- c_withvar (cvec_istr, v) {
+ c_fordefer (csmap_istr m1 = csmap_istr_init(), csmap_istr_del(&m1))
+ c_fordefer (cvec_istr v = cvec_istr_init(), cvec_istr_del(&v)) {
c_emplace(csmap_istr, m1, { { 40, "Zr" }, { 45, "Rh" } });
puts("The starting map m1 is (key, value):");
print_collection_csmap_istr(m1);
diff --git a/examples/csmap_insert.c b/examples/csmap_insert.c index e207a2a6..0f32e586 100644 --- a/examples/csmap_insert.c +++ b/examples/csmap_insert.c @@ -25,7 +25,7 @@ void print_istr(csmap_istr map) { int main()
{
// insert single values
- c_with (csmap_ii m1 = csmap_ii_init(), csmap_ii_del(&m1)) {
+ c_fordefer (csmap_ii m1 = csmap_ii_init(), csmap_ii_del(&m1)) {
csmap_ii_insert(&m1, 1, 10);
csmap_ii_insert(&m1, 2, 20);
@@ -52,9 +52,9 @@ int main() }
// The templatized version inserting a jumbled range
- // c_withvar(type, v) is shorthand for: c_with (type v = type_init(), type_del(&v))
- c_withvar (csmap_ii, m2)
- c_withvar (cvec_ii, v) {
+ // c_fordefer_var(type, v) is shorthand for: c_fordefer (type v = type_init(), type_del(&v))
+ c_fordefer (csmap_ii m2 = csmap_ii_init(), csmap_ii_del(&m2))
+ c_fordefer (cvec_ii v = cvec_ii_init(), cvec_ii_del(&v)) {
cvec_ii_push_back(&v, (cvec_ii_value_t){43, 294});
cvec_ii_push_back(&v, (cvec_ii_value_t){41, 262});
cvec_ii_push_back(&v, (cvec_ii_value_t){45, 330});
@@ -73,7 +73,7 @@ int main() }
// The templatized versions move-constructing elements
- c_withvar (csmap_istr, m3) {
+ c_fordefer (csmap_istr m3 = csmap_istr_init(), csmap_istr_del(&m3)) {
csmap_istr_value_t ip1 = {475, cstr_lit("blue")}, ip2 = {510, cstr_lit("green")};
// single element
@@ -88,7 +88,7 @@ int main() puts("");
}
- c_withvar (csmap_ii, m4) {
+ c_fordefer (csmap_ii m4 = csmap_ii_init(), csmap_ii_del(&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/demos.c b/examples/demos.c index 91daf1b1..a9fad4ab 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -9,7 +9,7 @@ void stringdemo1()
{
printf("\nSTRINGDEMO1\n");
- c_with (cstr cs = cstr_from("one-nine-three-seven-five"), cstr_del(&cs))
+ c_fordefer (cstr cs = cstr_from("one-nine-three-seven-five"), cstr_del(&cs))
{
printf("%s.\n", cs.str);
@@ -40,7 +40,7 @@ using_cvec(ix, int64_t); // ix is just an example tag name. void vectordemo1()
{
printf("\nVECTORDEMO1\n");
- c_with (cvec_ix bignums = cvec_ix_with_capacity(100), cvec_ix_del(&bignums))
+ c_fordefer (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)
@@ -64,7 +64,7 @@ using_cvec_str(); void vectordemo2()
{
printf("\nVECTORDEMO2\n");
- c_with (cvec_str names = cvec_str_init(), cvec_str_del(&names)) {
+ c_fordefer (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");
@@ -82,8 +82,8 @@ using_clist(ix, int); void listdemo1()
{
printf("\nLISTDEMO1\n");
- clist_ix nums = clist_ix_init(), nums2 = clist_ix_init();
- c_defer (clist_ix_del(&nums), clist_ix_del(&nums2))
+ c_fordefer (clist_ix nums = clist_ix_init(), clist_ix_del(&nums))
+ c_fordefer (clist_ix nums2 = clist_ix_init(), clist_ix_del(&nums2))
{
for (int i = 0; i < 10; ++i)
clist_ix_push_back(&nums, i);
@@ -142,7 +142,7 @@ using_cmap_strkey(si, int); // Shorthand macro for the general using_cmap expans void mapdemo2()
{
printf("\nMAPDEMO2\n");
- c_with (cmap_si nums = cmap_si_init(), cmap_si_del(&nums))
+ c_fordefer (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);
diff --git a/examples/ex_gauss1.c b/examples/ex_gauss1.c index 9b9285e6..d44c2b4e 100644 --- a/examples/ex_gauss1.c +++ b/examples/ex_gauss1.c @@ -30,8 +30,8 @@ int main() stc64_normalf_t dist = stc64_normalf_init(Mean, StdDev);
// Create and init histogram vec and map with defered destructors:
- c_withvar (cvec_e, vhist)
- c_withvar (cmap_i, mhist)
+ c_fordefer (cvec_e vhist = cvec_e_init(), cvec_e_del(&vhist))
+ c_fordefer (cmap_i mhist = cmap_i_init(), cmap_i_del(&mhist))
{
c_forrange (N) {
int index = (int) round( stc64_normalf(&rng, &dist) );
@@ -45,7 +45,7 @@ int main() cvec_e_sort(&vhist);
// Print the gaussian bar chart
- c_with (cstr bar = cstr_null, cstr_del(&bar))
+ c_fordefer (cstr bar = cstr_null, cstr_del(&bar))
c_foreach (i, cvec_e, vhist) {
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 9ff42ebe..23d8dd7a 100644 --- a/examples/ex_gauss2.c +++ b/examples/ex_gauss2.c @@ -21,7 +21,8 @@ int main() stc64_normalf_t dist = stc64_normalf_init(Mean, StdDev);
// Create and init histogram map with defered destruct
- c_withvar (csmap_i, mhist)
+ c_fordefer (csmap_i mhist = csmap_i_init(), csmap_i_del(&mhist))
+ c_fordefer (cstr bar = cstr_init(), cstr_del(&bar))
{
c_forrange (N) {
int index = (int) round( stc64_normalf(&rng, &dist) );
@@ -29,7 +30,6 @@ int main() }
// Print the gaussian bar chart
- c_withvar (cstr, bar)
c_foreach (i, csmap_i, mhist) {
size_t n = (size_t) (i.ref->second * StdDev * Scale * 2.5 / (float)N);
if (n > 0) {
diff --git a/examples/inits.c b/examples/inits.c index c1d64801..91f5c3c1 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -23,7 +23,7 @@ int main(void) {
// CVEC FLOAT / PRIORITY QUEUE
- c_withvar (cvec_f, floats) {
+ c_fordefer (cvec_f floats = cvec_f_init(), cvec_f_del(&floats)) {
c_emplace(cvec_f, floats, {4.0f, 2.0f, 5.0f, 3.0f, 1.0f});
c_foreach (i, cvec_f, floats) printf("%.1f ", *i.ref);
@@ -45,7 +45,7 @@ int main(void) // CMAP ID
int year = 2020;
- c_withvar (cmap_id, idnames) {
+ c_fordefer (cmap_id idnames = cmap_id_init(), cmap_id_del(&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));
@@ -57,7 +57,7 @@ int main(void) // CMAP CNT
- c_withvar (cmap_cnt, countries) {
+ c_fordefer (cmap_cnt countries = cmap_cnt_init(), cmap_cnt_del(&countries)) {
c_emplace(cmap_cnt, countries, {
{"Norway", 100},
{"Denmark", 50},
@@ -80,7 +80,7 @@ int main(void) // CVEC PAIR
- c_withvar (cvec_ip, pairs1) {
+ c_fordefer (cvec_ip pairs1 = cvec_ip_init(), cvec_ip_del(&pairs1)) {
c_emplace (cvec_ip, pairs1, {{5, 6}, {3, 4}, {1, 2}, {7, 8}});
cvec_ip_sort(&pairs1);
@@ -91,7 +91,7 @@ int main(void) // CLIST PAIR
- c_withvar (clist_ip, pairs2) {
+ c_fordefer (clist_ip pairs2 = clist_ip_init(), clist_ip_del(&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 85ebcf02..e4b027a9 100644 --- a/examples/list.c +++ b/examples/list.c @@ -8,7 +8,7 @@ int main() { int k;
const int n = 2000000;
- c_withvar (clist_fx, list) {
+ c_fordefer (clist_fx list = clist_fx_init(), clist_fx_del(&list)) {
stc64_t rng = stc64_init(1234);
stc64_uniformf_t dist = stc64_uniformf_init(100.0f, n);
int m = 0;
diff --git a/examples/list_erase.c b/examples/list_erase.c index 3526b5eb..a9d2b9d3 100644 --- a/examples/list_erase.c +++ b/examples/list_erase.c @@ -6,7 +6,7 @@ using_clist(i, int); int main ()
{
- c_with (clist_i L = clist_i_init(), clist_i_del(&L))
+ c_fordefer (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 dd5d8cc4..f80ac860 100644 --- a/examples/list_splice.c +++ b/examples/list_splice.c @@ -14,10 +14,11 @@ void print_ilist(const char* s, clist_i list) int main () { - c_var (clist_i, list1, {1, 2, 3, 4, 5}); - c_var (clist_i, list2, {10, 20, 30, 40, 50}); - c_defer (clist_i_del(&list1), clist_i_del(&list2)) + c_fordefer (clist_i list1 = clist_i_init(), clist_i_del(&list1)) + c_fordefer (clist_i list2 = clist_i_init(), clist_i_del(&list2)) { + c_emplace(clist_i, list1, {1, 2, 3, 4, 5}); + c_emplace(clist_i, list2, {10, 20, 30, 40, 50}); clist_i_iter_t it = clist_i_fwd(clist_i_begin(&list1), 2); it = clist_i_splice(&list1, it, &list2); diff --git a/examples/mapmap.c b/examples/mapmap.c index b4bb6beb..21b2cac9 100644 --- a/examples/mapmap.c +++ b/examples/mapmap.c @@ -9,7 +9,7 @@ using_cmap_str(); using_cmap_strkey(cfg, cmap_str, cmap_str_del, c_no_clone);
int main(void) {
- c_withvar (cmap_cfg, cfg) {
+ c_fordefer (cmap_cfg cfg = cmap_cfg_init(), cmap_cfg_del(&cfg)) {
cmap_str init = cmap_str_init();
cmap_str_emplace(&cmap_cfg_insert(&cfg, cstr_from("user"), init).ref->second, "name", "Joe");
cmap_str_emplace(&cmap_cfg_insert(&cfg, cstr_from("user"), init).ref->second, "groups", "proj1,proj3");
diff --git a/examples/mmap.c b/examples/mmap.c index c925db39..58511c37 100644 --- a/examples/mmap.c +++ b/examples/mmap.c @@ -26,7 +26,7 @@ void insert(csmap_m* mmap, int key, const char* str) int main()
{
- c_with (csmap_m mmap = csmap_m_init(), csmap_m_del(&mmap))
+ c_fordefer (csmap_m mmap = csmap_m_init(), csmap_m_del(&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 8d56119f..4b192e29 100644 --- a/examples/multimap.c +++ b/examples/multimap.c @@ -55,7 +55,7 @@ using_csmap_strkey(OL, clist_OL, clist_OL_del, c_no_clone); int main()
{
// Define the multimap with destructor defered to when block is completed.
- c_with (csmap_OL multimap = csmap_OL_init(), csmap_OL_del(&multimap))
+ c_fordefer (csmap_OL multimap = csmap_OL_init(), csmap_OL_del(&multimap))
{
clist_OL empty = clist_OL_init();
diff --git a/examples/phonebook.c b/examples/phonebook.c index 40a4b0fd..e755923f 100644 --- a/examples/phonebook.c +++ b/examples/phonebook.c @@ -39,14 +39,14 @@ int main(int argc, char **argv) {
c_static_assert(3 == 3, "hello");
- c_withvar (cset_str, names) {
+ c_fordefer (cset_str names = cset_str_init(), cset_str_del(&names)) {
c_emplace (cset_str, names, {"Hello", "Cool", "True"});
c_foreach (i, cset_str, names) printf("%s ", i.ref->str);
puts("");
}
bool erased;
- c_withvar (cmap_str, phone_book) {
+ c_fordefer (cmap_str phone_book = cmap_str_init(), cmap_str_del(&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 48fa5bbe..67f92c7b 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_with (cbits primes = sieveOfEratosthenes(n + 1), cbits_del(&primes)) {
+ c_fordefer (cbits primes = sieveOfEratosthenes(n + 1), cbits_del(&primes)) {
size_t np = cbits_count(primes);
clock_t t2 = clock();
diff --git a/examples/priority.c b/examples/priority.c index d0234dbc..e0865054 100644 --- a/examples/priority.c +++ b/examples/priority.c @@ -13,7 +13,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_withvar (cpque_i, heap)
+ c_fordefer (cpque_i heap = cpque_i_init(), cpque_i_del(&heap))
{
// Push ten million random numbers to priority queue
c_forrange (N)
diff --git a/examples/queue.c b/examples/queue.c index e3a74f33..d2687507 100644 --- a/examples/queue.c +++ b/examples/queue.c @@ -17,7 +17,7 @@ int main() { stc64_t rng = stc64_init(1234);
dist = stc64_uniform_init(0, n);
- c_withvar (cqueue_i, queue)
+ c_fordefer (cqueue_i queue = cqueue_i_init(), cqueue_i_del(&queue))
{
// Push ten million random numbers onto the queue.
c_forrange (n)
diff --git a/examples/replace.c b/examples/replace.c index b537ef88..69928917 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_defer (cstr_del(&s), cstr_del(&m)) {
+ c_fordefer ((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/stack.c b/examples/stack.c index 0815b580..83c8cc08 100644 --- a/examples/stack.c +++ b/examples/stack.c @@ -11,7 +11,7 @@ using_cstack(c, cvec_c); int main() {
cstack_i stack = cstack_i_init();
cstack_c chars = cstack_c_init();
- c_defer (cstack_i_del(&stack), cstack_c_del(&chars))
+ c_fordefer ((cstack_i_del(&stack), cstack_c_del(&chars)))
{
c_forrange (i, int, 101)
cstack_i_push(&stack, i*i);
diff --git a/examples/stc_astar.c b/examples/stc_astar.c index 11e8ca2b..ecca939f 100644 --- a/examples/stc_astar.c +++ b/examples/stc_astar.c @@ -83,9 +83,9 @@ astar(cstr maze, int width) cpque_pnt frontier = cpque_pnt_init();
csmap_step came_from = csmap_step_init();
csmap_cost cost_so_far = csmap_cost_init();
- c_defer (cpque_pnt_del(&frontier),
- csmap_step_del(&came_from),
- csmap_cost_del(&cost_so_far))
+ c_fordefer ((cpque_pnt_del(&frontier),
+ csmap_step_del(&came_from),
+ csmap_cost_del(&cost_so_far)))
{
cpque_pnt_push(&frontier, start);
csmap_cost_insert(&cost_so_far, start, 0);
diff --git a/examples/svmap.c b/examples/svmap.c index c45ff1ae..3087706e 100644 --- a/examples/svmap.c +++ b/examples/svmap.c @@ -9,7 +9,7 @@ int main() { csview fox = c_lit("The quick brown fox jumps over the lazy dog.");
printf("\"%s\", length=%zu\n", fox.str, fox.size);
- c_withvar (cmap_si, frequencies)
+ c_fordefer (cmap_si frequencies = cmap_si_init(), cmap_si_del(&frequencies))
{
// Non-emplace: cstr element API
cmap_si_insert(&frequencies, cstr_lit("thousand"), 1000);
diff --git a/examples/words.c b/examples/words.c index 6859f104..afc1f989 100644 --- a/examples/words.c +++ b/examples/words.c @@ -15,7 +15,7 @@ int main1() "this", "sentence", "is", "not", "a", "sentence", "this", "sentence", "is", "a", "hoax" }); - c_defer (clist_str_del(&lwords)) + c_fordefer (clist_str_del(&lwords)) { clist_str_push_back(&lwords, cstr_from_fmt("%.15f", sqrt(2))); c_foreach (w, clist_str, lwords) @@ -26,7 +26,7 @@ int main1() "this", "sentence", "is", "not", "a", "sentence", "this", "sentence", "is", "a", "hoax" }); - c_defer (cvec_str_del(&words)) + c_fordefer (cvec_str_del(&words)) { cmap_si word_map = cmap_si_init(); c_foreach (w, cvec_str, words) |
