diff options
Diffstat (limited to 'misc/examples')
| -rw-r--r-- | misc/examples/forfilter.c | 2 | ||||
| -rw-r--r-- | misc/examples/multidim.c | 18 | ||||
| -rw-r--r-- | misc/examples/prime.c | 2 |
3 files changed, 14 insertions, 8 deletions
diff --git a/misc/examples/forfilter.c b/misc/examples/forfilter.c index bd3d346d..05d0bc28 100644 --- a/misc/examples/forfilter.c +++ b/misc/examples/forfilter.c @@ -65,7 +65,7 @@ void demo2(void) c_AUTO (IVec, vector) { puts("demo2:"); - c_FORFILTER (x, crange, crange_object(INT64_MAX) + c_FORFILTER (x, crange, crange_literal(INT64_MAX) , c_FLT_SKIPWHILE(x, *x.ref != 11) && *x.ref % 2 != 0 , c_FLT_TAKE(x, 5)) diff --git a/misc/examples/multidim.c b/misc/examples/multidim.c index 2cf16b7f..99310847 100644 --- a/misc/examples/multidim.c +++ b/misc/examples/multidim.c @@ -1,13 +1,15 @@ -// Example from https://en.cppreference.com/w/cpp/container/mdspan +// Example based on https://en.cppreference.com/w/cpp/container/mdspan #define i_val int #include <stc/cstack.h> -#include <stc/algo/cspan.h> +#include <stc/cspan.h> #include <stdio.h> +using_cspan3(ispan, int); +/* using_cspan(ispan1, int, 1); using_cspan(ispan2, int, 2); using_cspan(ispan3, int, 3); - +*/ int main() { @@ -16,7 +18,7 @@ int main() cstack_int_push(&v, *i.ref); // View data as contiguous memory representing 12 ints - ispan1 ms1 = cspan_make(v.data, 12); + ispan1 ms1 = cspan_from(&v); // View data as contiguous memory representing 2 rows of 6 ints each ispan2 ms2 = cspan_make(v.data, 2, 6); // View the same data as a 3D array 2 x 3 x 2 @@ -27,12 +29,16 @@ int main() for (unsigned j=0; j != ms2.dim[1]; j++) *cspan_at(&ms2, i, j) = i*1000 + j; - // print data using 1D view + // print all items using 1D view + printf("all: "); for (unsigned i=0; i != ms1.dim[0]; i++) printf(" %d", *cspan_at(&ms1, i)); puts(""); - c_FOREACH (i, ispan1, ms1) + // or iterate a subspan... + ispan2 sub = cspan_3to2(&ms3, 1); + printf("sub: "); + c_FOREACH (i, ispan2, sub) printf(" %d", *i.ref); puts(""); diff --git a/misc/examples/prime.c b/misc/examples/prime.c index b4d81868..40ccc299 100644 --- a/misc/examples/prime.c +++ b/misc/examples/prime.c @@ -43,7 +43,7 @@ int main(void) puts(""); puts("Show the last 50 primes using a temporary crange generator:"); - c_FORFILTER (i, crange, crange_object(n - 1, 0, -2) + c_FORFILTER (i, crange, crange_literal(n - 1, 0, -2) , cbits_test(&primes, *i.ref>>1) , c_FLT_TAKE(i, 50)) { printf("%lld ", *i.ref); |
