diff options
| author | Tyge Løvset <[email protected]> | 2023-01-18 15:41:12 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-01-18 15:41:12 +0100 |
| commit | 90aab650b31febadcea45cfa60d0620b4d807ee9 (patch) | |
| tree | bfa10ce1480c37cdd1138b3579385359d1a77051 /misc/examples/printspan.c | |
| parent | 43fb253b75a3c76977317a111798c7be512bd032 (diff) | |
| download | STC-modified-90aab650b31febadcea45cfa60d0620b4d807ee9.tar.gz STC-modified-90aab650b31febadcea45cfa60d0620b4d807ee9.zip | |
Added cspan (1D) example.
Diffstat (limited to 'misc/examples/printspan.c')
| -rw-r--r-- | misc/examples/printspan.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/misc/examples/printspan.c b/misc/examples/printspan.c new file mode 100644 index 00000000..a897e669 --- /dev/null +++ b/misc/examples/printspan.c @@ -0,0 +1,42 @@ +// printspan.c + +#include <stdio.h> +#define i_val int +#include <stc/cvec.h> +#define i_val int +#include <stc/cstack.h> +#define i_val int +#include <stc/cdeq.h> +#include <stc/cspan.h> + +using_cspan(ispan, int, 1); + +void printMe(ispan container) { + printf("%d\n", (int)cspan_size(&container)); + c_FOREACH (e, ispan, container) printf("%d ", *e.ref); + puts(""); +} + +int main() { + c_AUTO (cvec_int, vec) + c_AUTO (cstack_int, stk) + c_AUTO (cdeq_int, deq) + { + int arr[] = {1, 2, 3, 4, 5}; + ispan sp = cspan_from_array(arr); + printMe((ispan)cspan_subspan(&sp, 1, 3)); + + printMe((ispan)cspan_from_list(int, {1, 2, 3, 4})); + + printMe((ispan)cspan_from_array(arr)); + + c_FORLIST (i, int, {1, 2, 3, 4, 5, 6}) cvec_int_push(&vec, *i.ref); + printMe((ispan)cspan_from(&vec)); + + c_FORLIST (i, int, {1, 2, 3, 4, 5, 6, 7}) cstack_int_push(&stk, *i.ref); + printMe((ispan)cspan_from(&stk)); + + c_FORLIST (i, int, {1, 2, 3, 4, 5, 6, 7, 8}) cdeq_int_push_front(&deq, *i.ref); + printMe((ispan)cspan_from(&deq)); + } +} |
