summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-09-16 11:46:33 +0200
committerTyge Løvset <[email protected]>2022-09-16 11:46:33 +0200
commit498679cde9565add37d685e16ea863db3d014a07 (patch)
tree61d0ec5f64b42ee6bf17729eb282a6cdb1847b14 /examples
parentd31f686e20c0f3731b1dc931f7f8e1d69c07ed4c (diff)
downloadSTC-modified-498679cde9565add37d685e16ea863db3d014a07.tar.gz
STC-modified-498679cde9565add37d685e16ea863db3d014a07.zip
Maintenance update.
Diffstat (limited to 'examples')
-rw-r--r--examples/list_erase.c27
-rw-r--r--examples/music_arc.c12
2 files changed, 20 insertions, 19 deletions
diff --git a/examples/list_erase.c b/examples/list_erase.c
index 9155e38d..71d1f55f 100644
--- a/examples/list_erase.c
+++ b/examples/list_erase.c
@@ -1,30 +1,31 @@
// erasing from clist
#include <stdio.h>
+#define i_type IList
#define i_val int
#include <stc/clist.h>
int main ()
{
- c_auto (clist_int, L)
+ c_with (IList L = IList_init(), IList_drop(&L))
{
c_forarray (int, i, {10, 20, 30, 40, 50})
- clist_int_push_back(&L, *i);
+ IList_push(&L, *i);
- c_foreach (x, clist_int, L)
+ c_foreach (x, IList, L)
printf("%d ", *x.ref);
puts("");
- // 10 20 30 40 50
- clist_int_iter it = clist_int_begin(&L); // ^
- clist_int_next(&it);
- it = clist_int_erase_at(&L, it); // 10 30 40 50
- // ^
- clist_int_iter end = clist_int_end(&L); //
- clist_int_next(&it);
- it = clist_int_erase_range(&L, it, end); // 10 30
- // ^
+ // 10 20 30 40 50
+ IList_iter it = IList_begin(&L); // ^
+ IList_next(&it);
+ it = IList_erase_at(&L, it); // 10 30 40 50
+ // ^
+ IList_iter end = IList_end(&L); //
+ IList_next(&it);
+ it = IList_erase_range(&L, it, end); // 10 30
+ // ^
printf("list contains:");
- c_foreach (x, clist_int, L)
+ c_foreach (x, IList, L)
printf(" %d", *x.ref);
puts("");
}
diff --git a/examples/music_arc.c b/examples/music_arc.c
index 6f9c1c72..a6b5d90f 100644
--- a/examples/music_arc.c
+++ b/examples/music_arc.c
@@ -29,20 +29,20 @@ void Song_drop(Song* s) {
// ... and a vector of it
#define i_type SongVec
#define i_val_arcbox SongArc
-#include <stc/cvec.h>
+#include <stc/cstack.h>
void example3()
{
- c_auto (SongVec, vec, vec2)
+ c_auto (SongVec, vec1, vec2)
{
c_forarray (Song, v, {
Song_from("Bob Dylan", "The Times They Are A Changing"),
Song_from("Aretha Franklin", "Bridge Over Troubled Water"),
Song_from("Thalia", "Entre El Mar y Una Estrella")
- }) SongVec_emplace(&vec, *v);
+ }) SongVec_emplace(&vec1, *v);
// Share all entries in vec with vec2, except Bob Dylan.
- c_foreach (s, SongVec, vec)
+ c_foreach (s, SongVec, vec1)
if (!cstr_equals(&s.ref->get->artist, "Bob Dylan"))
SongVec_push(&vec2, SongArc_clone(*s.ref));
@@ -53,10 +53,10 @@ void example3()
// SongVec_push(&vec2, SongArc_from(Song_from("Rihanna", "Stay")));
// We now have two vectors with some shared, some unique entries.
- c_forarray (SongVec, v, {vec, vec2}) {
+ c_forarray (SongVec, v, {vec1, vec2}) {
puts("VEC:");
c_foreach (s, SongVec, *v)
- printf(" %s - %s, REFS: %lu\n", cstr_str(&s.ref->get->artist),
+ printf(" %s - %s, REFS: %ld\n", cstr_str(&s.ref->get->artist),
cstr_str(&s.ref->get->title),
*s.ref->use_count);
}