summaryrefslogtreecommitdiffhomepage
path: root/docs/cspan_api.md
diff options
context:
space:
mode:
authortylov <[email protected]>2023-07-24 12:54:09 +0200
committertylov <[email protected]>2023-07-24 12:54:09 +0200
commitf1f0c01e798eb3217e62a43de660723173984547 (patch)
treeb3ebe91d4f3a7e24e79fb325982365af89c698cf /docs/cspan_api.md
parent4a37879119cd4d8b92c5dc578741052dd399f53f (diff)
downloadSTC-modified-f1f0c01e798eb3217e62a43de660723173984547.tar.gz
STC-modified-f1f0c01e798eb3217e62a43de660723173984547.zip
Improved an issue with cspan.
Diffstat (limited to 'docs/cspan_api.md')
-rw-r--r--docs/cspan_api.md10
1 files changed, 10 insertions, 0 deletions
diff --git a/docs/cspan_api.md b/docs/cspan_api.md
index 1312ae6d..51d72856 100644
--- a/docs/cspan_api.md
+++ b/docs/cspan_api.md
@@ -29,6 +29,7 @@ by default (define `STC_NDEBUG` or `NDEBUG` to disable).
```c
SpanType cspan_init(TYPE SpanType, {v1, v2, ...}); // make a 1-d cspan from values
SpanType cspan_from(STCContainer* cnt); // make a 1-d cspan from a cvec, cstack, cpque (heap)
+SpanType cspan_from_n(ValueType* ptr, intptr_t n); // make a 1-d cspan from a pointer and length
SpanType cspan_from_array(ValueType array[]); // make a 1-d cspan from a C array
intptr_t cspan_size(const SpanTypeN* self); // return number of elements
@@ -144,6 +145,7 @@ Slicing cspan without and with reducing the rank:
```c
#define i_implement
#include <c11/fmt.h>
+#include <stc/algorithm.h>
#include <stc/cspan.h>
using_cspan3(Span, int); // Shorthand to define Span, Span2, and Span3
@@ -164,6 +166,14 @@ int main(void)
fmt_print(" {}", *i.ref);
puts("");
+ // create span on-the-fly
+ int array[] = {3, 65, 4, 3, 7, 87, 45};
+ c_forfilter (i, ISpan, (ISpan)cspan_from_array(array),
+ c_flt_skip(i, 2) &&
+ c_flt_take(i, 3))
+ fmt_print(" {}", *i.ref);
+ puts("");
+
// slice without reducing rank:
Span3 ss3 = cspan_slice(Span3, &span3, {c_ALL}, {3,4}, {c_ALL});