summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--docs/carc_api.md1
-rw-r--r--docs/ccommon_api.md1
-rw-r--r--docs/cmap_api.md4
-rw-r--r--docs/crandom_api.md1
-rw-r--r--docs/cset_api.md1
-rw-r--r--docs/csmap_api.md4
-rw-r--r--docs/csset_api.md1
-rw-r--r--docs/cstr_api.md1
-rw-r--r--docs/csview_api.md26
-rw-r--r--docs/cvec_api.md2
-rw-r--r--include/stc/carc.h1
-rw-r--r--include/stc/cbox.h1
-rw-r--r--include/stc/csmap.h1
-rw-r--r--include/stc/cvec.h1
-rw-r--r--misc/benchmarks/various/sso_bench.cpp1
16 files changed, 36 insertions, 15 deletions
diff --git a/README.md b/README.md
index d699e1d1..e63a56e4 100644
--- a/README.md
+++ b/README.md
@@ -352,10 +352,10 @@ It is possible to generate single headers by executing the python script `src/si
Conveniently, `src\libstc.c` implements non-templated functions as shared symbols for **cstr**, **csview**,
**cbits** and **crand**. When building in shared mode (-DSTC_HEADER), you may include this file in your project,
-or define your own as descibed above.
+or define your own, e.g.:
```c
// stc_libs.c
-#define STC_IMPLEMENT
+#define STC_IMPLEMENT // implement all the following as shared objects
#include <stc/cstr.h>
#include "Point.h"
diff --git a/docs/carc_api.md b/docs/carc_api.md
index 48b64ff0..9f3d8cb9 100644
--- a/docs/carc_api.md
+++ b/docs/carc_api.md
@@ -78,6 +78,7 @@ bool carc_X_value_eq(const i_val* x, const i_val* y);
// Create two stacks with carcs to maps.
// Demonstrate sharing and cloning of maps.
// Show elements dropped.
+#define i_implement
#include <stc/cstr.h>
#define i_type Map
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md
index 56424989..cdd4ec87 100644
--- a/docs/ccommon_api.md
+++ b/docs/ccommon_api.md
@@ -470,6 +470,7 @@ return ok;
**Example 2**: Load each line of a text file into a vector of strings:
```c
#include <errno.h>
+#define i_implement
#include <stc/cstr.h>
#define i_val_str
diff --git a/docs/cmap_api.md b/docs/cmap_api.md
index 2c9ac8ed..69e547a0 100644
--- a/docs/cmap_api.md
+++ b/docs/cmap_api.md
@@ -114,6 +114,7 @@ bool c_memcmp_eq(const i_keyraw* a, const i_keyraw* b); // !
## Examples
```c
+#define i_implement
#include <stc/cstr.h>
#define i_key_str
@@ -157,6 +158,7 @@ The HEX of color BLACK is:[#000000]
### Example 2
This example uses a cmap with cstr as mapped value.
```c
+#define i_implement
#include <stc/cstr.h>
#define i_type IDMap
#define i_key int
@@ -267,6 +269,7 @@ Output:
### Example 5: Advanced
Key type is struct.
```c
+#define i_implement
#include <stc/cstr.h>
typedef struct {
@@ -335,6 +338,7 @@ In example 5 we needed to construct a lookup key which allocated strings, and th
In this example we use rawtype feature to make it even simpler to use. Note that we must use the emplace() methods
to add "raw" type entries (otherwise compile error):
```c
+#define i_implement
#include <stc/cstr.h>
typedef struct Viking {
diff --git a/docs/crandom_api.md b/docs/crandom_api.md
index 7281b2d7..74e23a6a 100644
--- a/docs/crandom_api.md
+++ b/docs/crandom_api.md
@@ -67,6 +67,7 @@ double crand_norm(crand_t* rng, crand_norm_t* dist);
```c
#include <time.h>
#include <stc/crand.h>
+#define i_implement
#include <stc/cstr.h>
// Declare int -> int sorted map. Uses typetag 'i' for ints.
diff --git a/docs/cset_api.md b/docs/cset_api.md
index 7243beb3..ecf87e5b 100644
--- a/docs/cset_api.md
+++ b/docs/cset_api.md
@@ -77,6 +77,7 @@ cset_X_value cset_X_value_clone(cset_X_value val);
## Example
```c
+#define i_implement
#include <stc/cstr.h>
#define i_type Strset
#define i_key_str
diff --git a/docs/csmap_api.md b/docs/csmap_api.md
index b1bb07c6..2fd9f6a5 100644
--- a/docs/csmap_api.md
+++ b/docs/csmap_api.md
@@ -102,8 +102,8 @@ void csmap_X_value_drop(csmap_X_value* pval);
## Examples
```c
+#define i_implement
#include <stc/cstr.h>
-
#define i_key_str // special macro for i_key = cstr, i_tag = str
#define i_val_str // ditto
#include <stc/csmap.h>
@@ -150,6 +150,7 @@ Translate a
[ [Run this code](https://godbolt.org/z/9d1PP77Pa) ]
```c
+#define i_implement
#include <stc/cstr.h>
#define i_type strmap
#define i_key_str
@@ -182,6 +183,7 @@ int main()
### Example 3
This example uses a csmap with cstr as mapped value.
```c
+#define i_implement
#include <stc/cstr.h>
#define i_type IDSMap
diff --git a/docs/csset_api.md b/docs/csset_api.md
index dafe6670..5695ecf6 100644
--- a/docs/csset_api.md
+++ b/docs/csset_api.md
@@ -76,6 +76,7 @@ csset_X_value csset_X_value_clone(csset_X_value val);
## Example
```c
+#define i_implement
#include <stc/cstr.h>
#define i_type SSet
diff --git a/docs/cstr_api.md b/docs/cstr_api.md
index 64ad002c..438dbf27 100644
--- a/docs/cstr_api.md
+++ b/docs/cstr_api.md
@@ -157,6 +157,7 @@ char* cstrnstrn(const char* str, const char* search, intptr_t slen, intpt
## Example
```c
+#define i_implement
#include <stc/cstr.h>
int main() {
diff --git a/docs/csview_api.md b/docs/csview_api.md
index ec3bf121..b697b7d6 100644
--- a/docs/csview_api.md
+++ b/docs/csview_api.md
@@ -20,8 +20,9 @@ description.
All csview definitions and prototypes are available by including a single header file.
```c
-#include <stc/cstr.h> // optional, include cstr+csview functionality
-#include <stc/csview.h>
+#define i_implement
+#include <stc/cstr.h>
+#include <stc/csview.h> // after cstr.h: include extra cstr-csview functions
```
## Methods
@@ -116,23 +117,24 @@ uint64_t csview_hash(const csview* x);
## Example
```c
+#define i_implement
#include <stc/cstr.h>
#include <stc/csview.h>
int main ()
{
cstr str1 = cstr_lit("We think in generalities, but we live in details.");
- // (quoting Alfred N. Whitehead)
+ // (quoting Alfred N. Whitehead)
- csview sv1 = cstr_substr(&str1, 3, 5); // "think"
- intptr_t pos = cstr_find(&str1, "live"); // position of "live" in str1
- csview sv2 = cstr_substr(&str1, pos, 4); // get "live"
- csview sv3 = cstr_slice(&str1, -8, -1); // get "details"
+ csview sv1 = cstr_substr_ex(&str1, 3, 5); // "think"
+ intptr_t pos = cstr_find(&str1, "live"); // position of "live" in str1
+ csview sv2 = cstr_substr_ex(&str1, pos, 4); // get "live"
+ csview sv3 = cstr_slice_ex(&str1, -8, -1); // get "details"
printf("%.*s %.*s %.*s\n",
c_SV(sv1), c_SV(sv2), c_SV(sv3));
cstr s1 = cstr_lit("Apples are red");
- cstr s2 = cstr_from_sv(cstr_substr(&s1, -3, 3)); // "red"
- cstr s3 = cstr_from_sv(cstr_substr(&s1, 0, 6)); // "Apples"
+ cstr s2 = cstr_from_sv(cstr_substr_ex(&s1, -3, 3)); // "red"
+ cstr s3 = cstr_from_sv(cstr_substr_ex(&s1, 0, 6)); // "Apples"
printf("%s %s\n", cstr_str(&s2), cstr_str(&s3));
c_drop(cstr, &str1, &s1, &s2, &s3);
@@ -146,8 +148,8 @@ red Apples
### Example 2: UTF8 handling
```c
-#include <stc/cstr.h>
-#include <stc/csview.h>
+#define i_extern
+#include <stc/cstr.h> // i_extern: implement cstr + dependencies (utf8)
int main()
{
@@ -181,7 +183,7 @@ void print_split(csview input, const char* sep)
printf("[%.*s]\n", c_SV(i.token));
puts("");
}
-
+#define i_implement
#include <stc/cstr.h>
#define i_val_str
#include <stc/cstack.h>
diff --git a/docs/cvec_api.md b/docs/cvec_api.md
index 841321b2..fa7bf8ca 100644
--- a/docs/cvec_api.md
+++ b/docs/cvec_api.md
@@ -148,6 +148,7 @@ sorted: 5 7 8 13 16 25
```
### Example 2
```c
+#define i_implement
#include <stc/cstr.h>
#define i_val_str
@@ -184,6 +185,7 @@ item: 2 elements so far
Container with elements of structs:
```c
+#define i_implement
#include <stc/cstr.h>
typedef struct {
diff --git a/include/stc/carc.h b/include/stc/carc.h
index 74205caf..756b604f 100644
--- a/include/stc/carc.h
+++ b/include/stc/carc.h
@@ -22,6 +22,7 @@
*/
/* carc: atomic reference counted shared_ptr
+#define i_implement
#include <stc/cstr.h>
typedef struct { cstr name, last; } Person;
diff --git a/include/stc/cbox.h b/include/stc/cbox.h
index 393b904b..699b32ac 100644
--- a/include/stc/cbox.h
+++ b/include/stc/cbox.h
@@ -23,6 +23,7 @@
*/
/* cbox: heap allocated boxed type
+#define i_implement
#include <stc/cstr.h>
typedef struct { cstr name, email; } Person;
diff --git a/include/stc/csmap.h b/include/stc/csmap.h
index fbfea8dd..e8138926 100644
--- a/include/stc/csmap.h
+++ b/include/stc/csmap.h
@@ -24,6 +24,7 @@
// Sorted/Ordered set and map - implemented as an AA-tree.
/*
#include <stdio.h>
+#define i_implement
#include <stc/cstr.h>
#define i_tag sx // Sorted map<cstr, double>
diff --git a/include/stc/cvec.h b/include/stc/cvec.h
index 1a0fb118..512dbf67 100644
--- a/include/stc/cvec.h
+++ b/include/stc/cvec.h
@@ -22,6 +22,7 @@
*/
/*
+#define i_implement
#include <stc/cstr.h>
#include <stc/forward.h>
diff --git a/misc/benchmarks/various/sso_bench.cpp b/misc/benchmarks/various/sso_bench.cpp
index 71d123e8..6d3d107a 100644
--- a/misc/benchmarks/various/sso_bench.cpp
+++ b/misc/benchmarks/various/sso_bench.cpp
@@ -3,6 +3,7 @@
#include <chrono>
#include <stc/crand.h>
+#define i_static
#include <stc/cstr.h>
#define i_type StcVec