summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/arcvec_erase.c
diff options
context:
space:
mode:
authortylov <[email protected]>2023-07-20 15:09:10 +0200
committertylov <[email protected]>2023-07-20 15:12:29 +0200
commit900295256d825fc323149cd223c49787f32a3696 (patch)
tree6c79cf4209e3975bb6865e2940b9cb56ea469c73 /misc/examples/arcvec_erase.c
parent224a04f7fa7549ed94d2a1415eb25829e39a7cca (diff)
downloadSTC-modified-900295256d825fc323149cd223c49787f32a3696.tar.gz
STC-modified-900295256d825fc323149cd223c49787f32a3696.zip
Moved examples to sub-directories. Added cotask1.c cotask2.c examples.
Diffstat (limited to 'misc/examples/arcvec_erase.c')
-rw-r--r--misc/examples/arcvec_erase.c50
1 files changed, 0 insertions, 50 deletions
diff --git a/misc/examples/arcvec_erase.c b/misc/examples/arcvec_erase.c
deleted file mode 100644
index ba54c1c7..00000000
--- a/misc/examples/arcvec_erase.c
+++ /dev/null
@@ -1,50 +0,0 @@
-#include <stdio.h>
-
-void show_drop(int* x) { printf("drop: %d\n", *x); }
-
-#define i_type Arc
-#define i_key int
-#define i_keydrop show_drop
-#define i_cmp_native // enable sort/search for int type
-#include <stc/carc.h> // Shared pointer to int
-
-#define i_type Vec
-#define i_keyboxed Arc
-#include <stc/cvec.h> // Vec: cvec<Arc>
-
-
-int main(void)
-{
- Vec vec = c_init(Vec, {2012, 1990, 2012, 2019, 2015});
-
- // clone the second 2012 and push it back.
- // note: cloning make sure that vec.data[2] has ref count 2.
- Vec_push(&vec, Arc_clone(vec.data[2]));
-
- printf("vec before erase :");
- c_foreach (i, Vec, vec)
- printf(" %d", *i.ref->get);
-
- 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_erase_at(&vec, it);
-
- int year = 2015;
- it = Vec_find(&vec, year); // Ok as tmp only.
- if (it.ref)
- Vec_erase_at(&vec, it);
-
- printf("vec after erase :");
- c_foreach (i, Vec, vec)
- printf(" %d", *i.ref->get);
-
- Vec_sort(&vec);
- printf("\nvec after sort :");
- c_foreach (i, Vec, vec)
- printf(" %d", *i.ref->get);
-
- puts("\nDone");
- Vec_drop(&vec);
-}