summaryrefslogtreecommitdiffhomepage
path: root/misc/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-03-22 17:32:21 +0100
committerTyge Løvset <[email protected]>2023-03-22 17:32:21 +0100
commite6a25eaaf4687ff99d0d719d0b32ad512156039e (patch)
tree6bc1730f6882eb054c6472361487a0be8b85c7aa /misc/examples
parent66429475ed6ac0deaba85989174e8880762d7888 (diff)
downloadSTC-modified-e6a25eaaf4687ff99d0d719d0b32ad512156039e.tar.gz
STC-modified-e6a25eaaf4687ff99d0d719d0b32ad512156039e.zip
Added c_foreach_r() macro for reverse iter of cvec, cdeq, cstack.
Moved c_find_if, c_erase_if, c_eraseremove_if to algo/filter.h Internals.
Diffstat (limited to 'misc/examples')
-rw-r--r--misc/examples/arcvec_erase.c4
-rw-r--r--misc/examples/csmap_find.c2
-rw-r--r--misc/examples/csset_erase.c2
-rw-r--r--misc/examples/demos.c2
-rw-r--r--misc/examples/forloops.c11
5 files changed, 11 insertions, 10 deletions
diff --git a/misc/examples/arcvec_erase.c b/misc/examples/arcvec_erase.c
index 38f11097..9c85d3ab 100644
--- a/misc/examples/arcvec_erase.c
+++ b/misc/examples/arcvec_erase.c
@@ -30,12 +30,12 @@ int main()
printf("\nerase vec.data[2]; or first matching value depending on compare.\n");
Vec_iter it;
it = Vec_find(&vec, *vec.data[2].get);
- if (it.ref != Vec_end(&vec).ref)
+ if (it.ref)
Vec_erase_at(&vec, it);
int year = 2015;
it = Vec_find(&vec, year); // Ok as tmp only.
- if (it.ref != Vec_end(&vec).ref)
+ if (it.ref)
Vec_erase_at(&vec, it);
printf("vec after erase :");
diff --git a/misc/examples/csmap_find.c b/misc/examples/csmap_find.c
index fe5558e2..863cdea0 100644
--- a/misc/examples/csmap_find.c
+++ b/misc/examples/csmap_find.c
@@ -33,7 +33,7 @@ void findit(csmap_istr c, csmap_istr_key val)
{
printf("Trying find() on value %d\n", val);
csmap_istr_iter result = csmap_istr_find(&c, val); // prefer contains() or get()
- if (result.ref != csmap_istr_end(&c).ref) {
+ if (result.ref) {
printf("Element found: "); print_elem(csmap_istr_value_toraw(result.ref)); puts("");
} else {
puts("Element not found.");
diff --git a/misc/examples/csset_erase.c b/misc/examples/csset_erase.c
index e8f2fec5..cf94156c 100644
--- a/misc/examples/csset_erase.c
+++ b/misc/examples/csset_erase.c
@@ -23,7 +23,7 @@ int main()
puts("");
printf("Erase values >= %d:\n", val);
- while (it.ref != csset_int_end(&set).ref)
+ while (it.ref)
it = csset_int_erase_at(&set, it);
c_foreach (k, csset_int, set)
diff --git a/misc/examples/demos.c b/misc/examples/demos.c
index d5336cbf..2a7f3888 100644
--- a/misc/examples/demos.c
+++ b/misc/examples/demos.c
@@ -152,7 +152,7 @@ void mapdemo2()
cmap_si_emplace_or_assign(&nums, "Groovy", 200); // overwrite previous
// iterate the map:
- for (cmap_si_iter i = cmap_si_begin(&nums); i.ref != cmap_si_end(&nums).ref; cmap_si_next(&i))
+ for (cmap_si_iter i = cmap_si_begin(&nums); i.ref; cmap_si_next(&i))
printf("long: %s: %d\n", cstr_str(&i.ref->first), i.ref->second);
// or rather use the short form:
diff --git a/misc/examples/forloops.c b/misc/examples/forloops.c
index 144ec637..2fe21c8b 100644
--- a/misc/examples/forloops.c
+++ b/misc/examples/forloops.c
@@ -35,11 +35,8 @@ int main()
printf(" %s", *i.ref);
puts("");
- 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 (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})
@@ -51,8 +48,12 @@ int main()
puts("\n\nc_foreach:");
c_foreach (i, IVec, vec)
printf(" %d", *i.ref);
- puts("");
+ puts("\n\nc_foreach_r: reverse");
+ c_foreach_r (i, IVec, vec)
+ printf(" %d", *i.ref);
+
+ puts("\n\nc_foreach in map:");
c_foreach (i, IMap, map)
printf(" (%d %d)", i.ref->first, i.ref->second);