diff options
| author | Tyge Løvset <[email protected]> | 2021-05-21 10:29:24 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-05-21 10:29:24 +0200 |
| commit | 29f36f157dbd25afd5da5876d2a37035c2f83c0c (patch) | |
| tree | 0833b6cd947b83af9b88d8067489311bd12b08d2 /docs/csview_api.md | |
| parent | 141c31a725ef0509998b208f4dda897347cbe4f2 (diff) | |
| download | STC-modified-29f36f157dbd25afd5da5876d2a37035c2f83c0c.tar.gz STC-modified-29f36f157dbd25afd5da5876d2a37035c2f83c0c.zip | |
Update csview_api.md
Diffstat (limited to 'docs/csview_api.md')
| -rw-r--r-- | docs/csview_api.md | 27 |
1 files changed, 1 insertions, 26 deletions
diff --git a/docs/csview_api.md b/docs/csview_api.md index 0a4595e0..525de2f1 100644 --- a/docs/csview_api.md +++ b/docs/csview_api.md @@ -115,36 +115,17 @@ using_cset_sv() // cmap<cstr, int> with csview as convertion type using_cmap_svkey(si, int); -// cvec<cstr> with csview as convertion type -using_cvec_sv(); int main() { csview text = c_lit("The length of this literal is evaluated at compile time and stored in csview text."); printf("%s\nLength: %zu\n\n", text.str, text.size); - // cvec of cstr elements, using csview as "emplace" type - c_var (cvec_sv, vec, { // defines vec with 3 cstr elements. - c_lit("Element 1"), // will be converted to cstr. - c_lit("Element 2"), - c_lit("Element 3") - }); - c_defer (cvec_sv_del(&vec)) // defer destruction to end of block. - { - // push constructed cstr directly - cvec_sv_push_back(&vec, cstr_lit("Second last element")); - // emplace constructs cstr from a csview - cvec_sv_emplace_back(&vec, c_lit("Last element")); - - c_foreach (i, cvec_sv, vec) - printf("%s\n", i.ref->str); - } - c_withvar (cmap_si, map) // defines map and defers destruction. { cmap_si_emplace(&map, c_lit("hello"), 100); cmap_si_emplace(&map, c_lit("world"), 200); - cmap_si_emplace(&map, c_lit("gone mad"), 300); + cmap_si_emplace(&map, c_lit("hello"), 300); // already in map, ignored // Efficient lookup: no string allocation or strlen() takes place: cmap_si_value_t* v = cmap_si_get(&map, c_lit("world")); @@ -157,12 +138,6 @@ Output: A long and winded literal string Length: 32 -Great -Fantastic -Sensational -Second last element -Last element - world: 200 ``` |
