summaryrefslogtreecommitdiffhomepage
path: root/docs
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-10-20 16:17:33 +0200
committerTyge Løvset <[email protected]>2022-10-20 16:17:33 +0200
commit14f67d1936fa76be436eaaee739861268ca534f7 (patch)
treec365789721d90cb09c311f0a65527ba31832da8b /docs
parent79d43229e64c53cd8b358a02a58fdbe124aa5e0f (diff)
downloadSTC-modified-14f67d1936fa76be436eaaee739861268ca534f7.tar.gz
STC-modified-14f67d1936fa76be436eaaee739861268ca534f7.zip
Switch from #define i_val_bind to i_val_class and i_key_class.
i_val_bind/i_key_bind is deprecated but available for now.
Diffstat (limited to 'docs')
-rw-r--r--docs/carc_api.md2
-rw-r--r--docs/cmap_api.md8
-rw-r--r--docs/cvec_api.md36
3 files changed, 23 insertions, 23 deletions
diff --git a/docs/carc_api.md b/docs/carc_api.md
index 08070889..c8248b67 100644
--- a/docs/carc_api.md
+++ b/docs/carc_api.md
@@ -84,7 +84,7 @@ bool carc_X_value_eq(const i_val* x, const i_val* y);
#include <stc/csmap.h>
#define i_type Arc // (atomic) ref. counted pointer
-#define i_val_bind Map // Note i_val_bind: Map is a "class", i.e. has clone, drop functions.
+#define i_val_class Map // Note i_val_class: Map is a "class", i.e. has clone, drop functions.
#define i_valdrop(p) (printf("drop Arc:\n"), Map_drop(p)) // override Map_drop(p):
#include <stc/carc.h>
diff --git a/docs/cmap_api.md b/docs/cmap_api.md
index 10bca836..119b72f2 100644
--- a/docs/cmap_api.md
+++ b/docs/cmap_api.md
@@ -298,10 +298,10 @@ static inline void Viking_drop(Viking* vk) {
}
#define i_type Vikings
-#define i_key_bind Viking
+#define i_key_class Viking
#define i_val int
/*
- i_key_bind implies these defines, unless they are already defined:
+ i_key_class implies these defines, unless they are already defined:
#define i_cmp Viking_cmp
#define i_hash Viking_hash
#define i_keyclone Viking_clone
@@ -377,7 +377,7 @@ static inline RViking Viking_toraw(const Viking* vp) {
// With this in place, we define the Viking => int hash map type:
#define i_type Vikings
-#define i_key_bind Viking
+#define i_key_class Viking
#define i_keyraw RViking
#define i_keyfrom Viking_from
#define i_opt c_no_clone // disable map cloning
@@ -385,7 +385,7 @@ static inline RViking Viking_toraw(const Viking* vp) {
#define i_val int
#include <stc/cmap.h>
/*
- i_key_bind implies these defines, unless they are already defined:
+ i_key_class implies these defines, unless they are already defined:
#define i_cmp RViking_cmp
//#define i_hash RViking_hash // already defined above.
//#define i_keyclone Viking_clone // not used because c_no_clone
diff --git a/docs/cvec_api.md b/docs/cvec_api.md
index c9442bb1..50fb4448 100644
--- a/docs/cvec_api.md
+++ b/docs/cvec_api.md
@@ -156,19 +156,21 @@ sorted: 5 7 8 13 16 25
int main() {
cvec_str names = cvec_str_init();
+
cvec_str_emplace(&names, "Mary");
cvec_str_emplace(&names, "Joe");
cstr_assign(&names.data[1], "Jake"); // replace "Joe".
cstr tmp = cstr_from_fmt("%d elements so far", cvec_str_size(names));
- // emplace() will not compile if adding a new cstr type. Use push_back():
- cvec_str_push(&names, tmp); // tmp is moved to names, do not drop() it.
+ // cvec_str_emplace() only accept const char*, so use push():
+ cvec_str_push(&names, tmp); // tmp is "moved" to names (must not be dropped).
- printf("%s\n", cstr_str(&names.data[1])); // Access the second element
+ printf("%s\n", cstr_str(&names.data[1])); // Access second element
c_foreach (i, cvec_str, names)
printf("item: %s\n", cstr_str(i.ref));
+
cvec_str_drop(&names);
}
```
@@ -192,7 +194,7 @@ typedef struct {
int User_cmp(const User* a, const User* b) {
int c = strcmp(cstr_str(&a->name), cstr_str(&b->name));
- return c != 0 ? c : a->id - b->id;
+ return c ? c : a->id - b->id;
}
void User_drop(User* self) {
cstr_drop(&self->name);
@@ -202,24 +204,22 @@ User User_clone(User user) {
return user;
}
-// Declare a memory managed, clonable vector of users.
-// Note that cvec_u_emplace_back() will clone input:
-#define i_val User
-#define i_cmp User_cmp
-#define i_valdrop User_drop
-#define i_valclone User_clone
-#define i_tag u
+// Declare a managed, clonable vector of users.
+#define i_type UVec
+#define i_val_class User // User is a "class" as it has _cmp, _clone and _drop functions.
#include <stc/cvec.h>
int main(void) {
- cvec_u vec = cvec_u_init();
- cvec_u_push(&vec, (User) {cstr_new("admin"), 0});
- cvec_u_push(&vec, (User) {cstr_new("joe"), 1});
+ UVec vec = UVec_init();
+ UVec_push(&vec, (User){cstr_new("mary"), 0});
+ UVec_push(&vec, (User){cstr_new("joe"), 1});
+ UVec_push(&vec, (User){cstr_new("admin"), 2});
- cvec_u vec2 = cvec_u_clone(vec);
- c_foreach (i, cvec_u, vec2)
+ UVec vec2 = UVec_clone(vec);
+
+ c_foreach (i, UVec, vec2)
printf("%s: %d\n", cstr_str(&i.ref->name), i.ref->id);
- c_drop(cvec_u, &vec, &vec2); // cleanup
+ c_drop(UVec, &vec, &vec2); // cleanup
}
-```
+``` \ No newline at end of file