summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/printspan.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-01-20 10:00:29 +0100
committerTyge Løvset <[email protected]>2023-01-20 10:00:29 +0100
commit9e6b763fb28c783b8d856442a6929026257bff92 (patch)
tree016867546f86d5260bd0657c8d8df1be3b2c3bea /misc/examples/printspan.c
parentf8accdbcee0b397ad6ba2f2c2c64575a003e71e5 (diff)
downloadSTC-modified-9e6b763fb28c783b8d856442a6929026257bff92.tar.gz
STC-modified-9e6b763fb28c783b8d856442a6929026257bff92.zip
Renamed macro function c_initialize() to c_init().
Minor internal improvements.
Diffstat (limited to 'misc/examples/printspan.c')
-rw-r--r--misc/examples/printspan.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/misc/examples/printspan.c b/misc/examples/printspan.c
index 6292cecf..8d0b0321 100644
--- a/misc/examples/printspan.c
+++ b/misc/examples/printspan.c
@@ -12,40 +12,43 @@
#include <stc/cset.h>
#include <stc/cspan.h>
-using_cspan(ispan, int, 1);
+using_cspan(intspan, int, 1);
-void printMe(ispan container) {
- printf("%d\n", (int)cspan_size(&container));
- c_FOREACH (e, ispan, container) printf("%d ", *e.ref);
+void printMe(intspan container) {
+ printf("%d:", (int)cspan_size(&container));
+ c_FOREACH (e, intspan, container) printf(" %d", *e.ref);
puts("");
}
-int main() {
+int main()
+{
c_AUTO (cvec_int, vec)
c_AUTO (cstack_int, stk)
c_AUTO (cdeq_int, deq)
c_AUTO (cset_str, set)
{
- int arr[] = {1, 2, 3, 4, 5};
- ispan sp = cspan_from_array(arr);
- printMe((ispan)cspan_subspan(&sp, 1, 3));
+ printMe( c_init(intspan, {1, 2, 3}) );
- printMe(c_initialize(ispan, {1, 2, 3, 4}));
+ int arr[] = {1, 2, 3, 4, 5, 6};
+ intspan span = cspan_from_array(arr);
+ printMe( (intspan)cspan_subspan(&span, 1, 4) );
- printMe((ispan)cspan_from_array(arr));
+ c_FORLIST (i, int, {1, 2, 3, 4, 5})
+ cvec_int_push(&vec, *i.ref);
+ printMe( (intspan)cspan_from(&vec) );
- c_FORLIST (i, int, {1, 2, 3, 4, 5, 6}) cvec_int_push(&vec, *i.ref);
- printMe((ispan)cspan_from(&vec));
+ printMe( span );
- stk = c_initialize(cstack_int, {1, 2, 3, 4, 5, 6, 7});
- printMe((ispan)cspan_from(&stk));
+ stk = c_init(cstack_int, {1, 2, 3, 4, 5, 6, 7});
+ printMe( (intspan)cspan_from(&stk) );
- deq = c_initialize(cdeq_int, {1, 2, 3, 4, 5, 6, 7, 8});
- printMe((ispan)cspan_from(&deq));
+ deq = c_init(cdeq_int, {1, 2, 3, 4, 5, 6, 7, 8});
+ printMe( (intspan)cspan_from(&deq) );
- set = c_initialize(cset_str, {"1", "2", "3", "4", "5", "6", "7", "8", "9"});
- printf("%d\n", (int)cset_str_size(&set));
- c_FOREACH (e, cset_str, set) printf("%s ", cstr_str(e.ref));
+ set = c_init(cset_str, {"1", "2", "3", "4", "5", "6", "7", "8", "9"});
+ printf("%d:", (int)cset_str_size(&set));
+ c_FOREACH (e, cset_str, set)
+ printf(" %s", cstr_str(e.ref));
puts("");
}
}