summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--docs/csmap_api.md71
-rw-r--r--src/singleupdate.sh27
3 files changed, 65 insertions, 37 deletions
diff --git a/README.md b/README.md
index 13cedb10..15778ddd 100644
--- a/README.md
+++ b/README.md
@@ -197,7 +197,7 @@ For user-defined struct elements, `i_cmp` compare function should be defined as
only works for integral types. *Alternatively, `#define i_opt c_no_cmp` to disable sorting and searching*. Similarily, if an element destructor `i_valdrop` is defined, `i_valclone` function is required.
*Alternatively `#define i_opt c_no_clone` to disable container cloning.*
-Let's make a vector of vectors, which can be cloned. All of its element vectors will be destroyed when destroying the Vec2D.
+Let's make a vector of vectors, which can be cloned. All of its element vectors will be destroyed when destroying the Vec2D. [ [Run this code](https://godbolt.org/z/5EY56qnfM) ]
```c
#include <stdio.h>
@@ -231,7 +231,7 @@ int main(void)
c_drop(Vec2D, &vec, &clone); // Cleanup all (6) vectors.
}
```
-This example uses four different container types:
+This example uses four different container types: [ [Run this code](https://godbolt.org/z/x5YKeMrEh) ]
```c
#include <stdio.h>
diff --git a/docs/csmap_api.md b/docs/csmap_api.md
index 0eff8c26..59914369 100644
--- a/docs/csmap_api.md
+++ b/docs/csmap_api.md
@@ -142,7 +142,42 @@ The HEX of color RED is:[#FF0000]
The HEX of color BLACK is:[#000000]
```
+
### Example 2
+Translate a
+[C++ example using *insert* and *emplace*](https://en.cppreference.com/w/cpp/container/map/try_emplace)
+ to STC: [ [Run this code](https://godbolt.org/z/9d1PP77Pa) ]
+```c
+#include <stc/cstr.h>
+#define i_type strmap
+#define i_key_str
+#define i_val_str
+#include <stc/csmap.h>
+
+static void print_node(const strmap_value* node) {
+ printf("[%s] = %s\n", cstr_str(&node->first), cstr_str(&node->second));
+}
+
+static void print_result(strmap_result result) {
+ printf("%s", result.inserted ? "inserted: " : "ignored: ");
+ print_node(result.ref);
+}
+
+int main()
+{
+ strmap m = {0};
+
+ print_result( strmap_emplace(&m, "a", "a") );
+ print_result( strmap_emplace(&m, "b", "abcd") );
+ print_result( strmap_insert(&m, cstr_from("c"), cstr_with_size(10, 'c') ) );
+ print_result( strmap_emplace(&m, "c", "Won't be inserted") );
+
+ c_foreach (p, strmap, m) { print_node(p.ref); }
+ strmap_drop(&m);
+}
+```
+
+### Example 3
This example uses a csmap with cstr as mapped value.
```c
#include <stc/cstr.h>
@@ -179,7 +214,7 @@ Output:
120: #cc7744ff
```
-### Example 3
+### Example 4
Demonstrate csmap with plain-old-data key type Vec3i and int as mapped type: csmap<Vec3i, int>.
```c
typedef struct { int x, y, z; } Vec3i;
@@ -220,37 +255,3 @@ Output:
{ 100, 0, 0 }: 1
{ 100, 100, 100 }: 4
```
-
-### Example 4
-Inverse: demonstrate csmap with mapped POD type Vec3i: csmap<int, Vec3i>:
-```c
-typedef struct { int x, y, z; } Vec3i;
-
-#define i_key int
-#define i_val Vec3i
-#define i_tag iv
-#include <stc/csmap.h>
-#include <stdio.h>
-
-int main()
-{
- csmap_iv imap = {0};
-
- csmap_iv_insert(&imap, 1, (Vec3i){100, 0, 0});
- csmap_iv_insert(&imap, 2, (Vec3i){0, 100, 0});
- csmap_iv_insert(&imap, 3, (Vec3i){0, 0, 100});
- csmap_iv_insert(&imap, 4, (Vec3i){100, 100, 100});
-
- c_forpair (n, v, csmap_iv, imap)
- printf("%d: { %3d, %3d, %3d }\n", *_.n, _.v->x, _.v->y, _.v->z);
-
- csmap_iv_drop(&imap);
-}
-```
-Output:
-```c
-1: { 100, 0, 0 }
-2: { 0, 100, 0 }
-3: { 0, 0, 100 }
-4: { 100, 100, 100 }
-```
diff --git a/src/singleupdate.sh b/src/singleupdate.sh
new file mode 100644
index 00000000..d9a16568
--- /dev/null
+++ b/src/singleupdate.sh
@@ -0,0 +1,27 @@
+d=$(git rev-parse --show-toplevel)
+mkdir -p $d/../stcsingle/c11 $d/../stcsingle/stc
+python singleheader.py $d/include/c11/print.h > $d/../stcsingle/c11/print.h
+python singleheader.py $d/include/stc/calgo.h > $d/../stcsingle/stc/calgo.h
+python singleheader.py $d/include/stc/carc.h > $d/../stcsingle/stc/carc.h
+python singleheader.py $d/include/stc/cbits.h > $d/../stcsingle/stc/cbits.h
+python singleheader.py $d/include/stc/cbox.h > $d/../stcsingle/stc/cbox.h
+python singleheader.py $d/include/stc/ccommon.h > $d/../stcsingle/stc/ccommon.h
+python singleheader.py $d/include/stc/cdeq.h > $d/../stcsingle/stc/cdeq.h
+python singleheader.py $d/include/stc/clist.h > $d/../stcsingle/stc/clist.h
+python singleheader.py $d/include/stc/cmap.h > $d/../stcsingle/stc/cmap.h
+python singleheader.py $d/include/stc/coption.h > $d/../stcsingle/stc/coption.h
+python singleheader.py $d/include/stc/cpque.h > $d/../stcsingle/stc/cpque.h
+python singleheader.py $d/include/stc/cqueue.h > $d/../stcsingle/stc/cqueue.h
+python singleheader.py $d/include/stc/crand.h > $d/../stcsingle/stc/crand.h
+python singleheader.py $d/include/stc/cregex.h > $d/../stcsingle/stc/cregex.h
+python singleheader.py $d/include/stc/cset.h > $d/../stcsingle/stc/cset.h
+python singleheader.py $d/include/stc/csmap.h > $d/../stcsingle/stc/csmap.h
+python singleheader.py $d/include/stc/cspan.h > $d/../stcsingle/stc/cspan.h
+python singleheader.py $d/include/stc/csset.h > $d/../stcsingle/stc/csset.h
+python singleheader.py $d/include/stc/cstack.h > $d/../stcsingle/stc/cstack.h
+python singleheader.py $d/include/stc/cstr.h > $d/../stcsingle/stc/cstr.h
+python singleheader.py $d/include/stc/csview.h > $d/../stcsingle/stc/csview.h
+python singleheader.py $d/include/stc/cvec.h > $d/../stcsingle/stc/cvec.h
+python singleheader.py $d/include/stc/extend.h > $d/../stcsingle/stc/extend.h
+python singleheader.py $d/include/stc/forward.h > $d/../stcsingle/stc/forward.h
+echo "stcsingle headers updated" \ No newline at end of file