summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-01-19 21:20:16 +0100
committerTyge Løvset <[email protected]>2023-01-19 21:20:16 +0100
commitf8accdbcee0b397ad6ba2f2c2c64575a003e71e5 (patch)
tree1ec8e47eb15fd69d53e394e143c36d7f3500643e
parent5aa48d538569463ffeda976d21f79edc5f276be4 (diff)
downloadSTC-modified-f8accdbcee0b397ad6ba2f2c2c64575a003e71e5.tar.gz
STC-modified-f8accdbcee0b397ad6ba2f2c2c64575a003e71e5.zip
Finish last commit. Most safe function macros are now preferred lowercase, whereas flow control macros (c_FOREACH, ..) are preferred uppercase.
-rw-r--r--docs/ccommon_api.md84
-rw-r--r--docs/cmap_api.md2
-rw-r--r--docs/csview_api.md2
-rw-r--r--docs/cvec_api.md2
-rw-r--r--include/stc/algo/crange.h2
-rw-r--r--include/stc/algo/csort.h6
-rw-r--r--include/stc/algo/filter.h12
-rw-r--r--include/stc/carc.h4
-rw-r--r--include/stc/cbits.h4
-rw-r--r--include/stc/cbox.h6
-rw-r--r--include/stc/ccommon.h33
-rw-r--r--include/stc/cdeq.h8
-rw-r--r--include/stc/clist.h8
-rw-r--r--include/stc/cmap.h10
-rw-r--r--include/stc/cpque.h2
-rw-r--r--include/stc/crandom.h4
-rw-r--r--include/stc/csmap.h4
-rw-r--r--include/stc/cspan.h13
-rw-r--r--include/stc/cstack.h4
-rw-r--r--include/stc/cstr.h16
-rw-r--r--include/stc/csview.h10
-rw-r--r--include/stc/cvec.h10
-rw-r--r--include/stc/priv/lowcase.h26
-rw-r--r--misc/archived/csmap.h6
-rw-r--r--misc/archived/cstr.h4
-rw-r--r--misc/examples/box.c2
-rw-r--r--misc/examples/city.c2
-rw-r--r--misc/examples/forfilter.c20
-rw-r--r--misc/examples/forloops.c10
-rw-r--r--misc/examples/functor.c2
-rw-r--r--misc/examples/music_arc.c2
-rw-r--r--misc/examples/new_sptr.c2
-rw-r--r--misc/examples/person_arc.c2
-rw-r--r--misc/examples/prime.c2
-rw-r--r--misc/examples/sso_substr.c2
-rw-r--r--misc/examples/vikings.c4
36 files changed, 170 insertions, 162 deletions
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md
index b610ff04..6f09a130 100644
--- a/docs/ccommon_api.md
+++ b/docs/ccommon_api.md
@@ -225,10 +225,10 @@ Iterate containers with stop-criteria and chained range filtering.
| Built-in filter | Description |
|:----------------------------------|:-------------------------------------|
-| `c_FLT_SKIP(it, numItems)` | Skip numItems |
-| `c_FLT_TAKE(it, numItems)` | Take numItems |
-| `c_FLT_SKIPWHILE(it, predicate)` | Skip items until predicate is false |
-| `c_FLT_TAKEWHILE(it, predicate)` | Take items until predicate is false |
+| `c_flt_skip(it, numItems)` | Skip numItems |
+| `c_flt_take(it, numItems)` | Take numItems |
+| `c_flt_skipwhile(it, predicate)` | Skip items until predicate is false |
+| `c_flt_takewhile(it, predicate)` | Take items until predicate is false |
`it.index` holds the index of the source item, and `it.count` the current number of items taken.
```c
@@ -249,9 +249,9 @@ int main() {
c_FORFILTER (i, IVec, vec,
isOdd(*i.ref)
- && c_FLT_SKIP(i, 100) // built-in
+ && c_flt_skip(i, 100) // built-in
&& isPrime(*i.ref)
- , c_FLT_TAKE(i, 10)) { // breaks loop on false.
+ , c_flt_take(i, 10)) { // breaks loop on false.
printf(" %d", *i.ref);
}
puts("");
@@ -259,7 +259,18 @@ int main() {
}
// Out: 1000211 1000213 1000231 1000249 1000253 1000273 1000289 1000291 1000303 1000313
```
-Note that `c_FLT_TAKE()` is given as an optional argument, which makes the loop stop when it becomes false (for efficiency). Chaining it after `isPrime()` instead will give same result, but the full input is processed.
+Note that `c_flt_take()` is given as an optional argument, which makes the loop stop when it becomes false (for efficiency). Chaining it after `isPrime()` instead will give same result, but the full input is processed.
+
+### c_initialize
+
+Create a container from a literal initializer list.
+**c_initialize** a container or a cspan with an initializer list.
+```c
+#define i_val_str
+#include <stc/cset.h>
+...
+cset_str myset = c_initialize(cset_str, {"This", "is", "the", "story"});
+```
### crange
**crange** is a number sequence generator type. The **crange_value** type is `long long`. Below, *start*, *stop*, *step* are type *crange_value*:
@@ -284,48 +295,33 @@ c_FORFILTER (i, crange, r1
printf("2");
c_FORFILTER (i, crange, crange_literal(3, INT64_MAX, 2)
, isPrime(*i.ref)
- , c_FLT_TAKE(10))
+ , c_flt_take(10))
printf(" %lld", *i.ref);
// 2 3 5 7 11 13 17 19 23 29 31
```
-### c_FIND_IF, c_ERASE_IF
+### c_find_if, c_erase_if, c_swap, c_drop
Find or erase linearily in containers using a predicate
```c
// Search vec for first value > 2:
cvec_i_iter i;
-c_FIND_IF(i, cvec_i, vec, *i.ref > 2);
+c_find_if(i, cvec_i, vec, *i.ref > 2);
if (i.ref) printf("%d\n", *i.ref);
// Search map for a string containing "hello" and erase it:
cmap_str_iter it, it1 = ..., it2 = ...;
-c_FIND_IF(it, csmap_str, it1, it2, cstr_contains(it.ref, "hello"));
+c_find_if(it, csmap_str, it1, it2, cstr_contains(it.ref, "hello"));
if (it.ref) cmap_str_erase_at(&map, it);
// Erase all strings containing "hello":
// Note 1: iter i need not be declared.
// Note 2: variables index and count can be accessed in predicate.
-c_ERASE_IF(i, csmap_str, map, cstr_contains(i.ref, "hello"));
-```
+c_erase_if(i, csmap_str, map, cstr_contains(i.ref, "hello"));
-### c_NEW, c_ALLOC, c_ALLOC_N, c_DROP
+// Safe macro for swapping internals of two objects of same type:
+c_swap(cmap_int, &map1, &map2);
-| Usage | Meaning |
-|:-------------------------------|:----------------------------------------|
-| `c_NEW (type, value)` | Move value to a new object on the heap |
-| `c_ALLOC (type)` | `(type *) c_MALLOC(sizeof(type))` |
-| `c_ALLOC_N (type, N)` | `(type *) c_MALLOC((N)*sizeof(type))` |
-| `c_DROP (ctype, &c1, ..., &cN)` | `ctype_drop(&c1); ... ctype_drop(&cN)` |
-
-```c
-struct Pnt { double x, y, z; };
-struct Pnt *pnt = c_NEW (struct Pnt, {1.2, 3.4, 5.6});
-c_FREE(pnt);
-
-int* array = c_ALLOC_N (int, 100);
-c_FREE(array);
-
-cstr a = cstr_lit("Hello"), b = cstr_lit("World");
-c_DROP(cstr, &a, &b);
+// Drop multiple containers of same type:
+c_drop(cvec_i, &vec1, &vec2, &vec3);
```
### General predefined template parameter functions
@@ -341,17 +337,29 @@ bool crawstr_eq(const crawstr* x, const crawstr* y);
uint64_t crawstr_hash(const crawstr* x);
```
-### c_MALLOC, c_CALLOC, c_REALLOC, c_FREE
+### c_NEW, c_ALLOC, c_ALLOC_N
+
+| Usage | Meaning |
+|:----------------------------|:-------------------------------------------|
+| `c_NEW (type, value)` | Allocate and init a new object on the heap |
+| `c_ALLOC (type)` | `(type *) c_MALLOC(sizeof(type))` |
+| `c_ALLOC_N (type, N)` | `(type *) c_MALLOC((N)*sizeof(type))` |
+
+```c
+struct Pnt { double x, y, z; };
+struct Pnt *pnt = c_NEW(struct Pnt, {1.2, 3.4, 5.6});
+c_FREE(pnt);
+
+int* array = c_ALLOC_N(int, 100);
+c_FREE(array);
+```
+
+### c_MALLOC, c_CALLOC, c_REALLOC, c_FREE: customizable allocators
Memory allocator for the entire library. Macros can be overridden by the user.
-### c_SWAP, c_ARRAYLEN
-- **c_SWAP(T, xp, yp)**: Safe macro for swapping internals of two objects of same type.
+### c_ARRAYLEN
- **c_ARRAYLEN(array)**: Return number of elements in an array.
```c
-cmap_int map1 = {0}, map2 = {0};
-...
-c_SWAP(cmap_int, &map1, &map2);
-
int array[] = {1, 2, 3, 4};
size_t n = c_ARRAYLEN(array);
```
diff --git a/docs/cmap_api.md b/docs/cmap_api.md
index a33715fc..3848e67e 100644
--- a/docs/cmap_api.md
+++ b/docs/cmap_api.md
@@ -353,7 +353,7 @@ typedef struct Viking {
} Viking;
static inline void Viking_drop(Viking* v) {
- c_DROP(cstr, &v->name, &v->country);
+ c_drop(cstr, &v->name, &v->country);
}
// Define Viking raw struct with cmp, hash, and convertion functions between Viking and RViking structs:
diff --git a/docs/csview_api.md b/docs/csview_api.md
index b5508ace..4085a708 100644
--- a/docs/csview_api.md
+++ b/docs/csview_api.md
@@ -135,7 +135,7 @@ int main ()
cstr s3 = cstr_from_sv(cstr_substr(&s1, 0, 6)); // "Apples"
printf("%s %s\n", cstr_str(&s2), cstr_str(&s3));
- c_DROP(cstr, &str1, &s1, &s2, &s3);
+ c_drop(cstr, &str1, &s1, &s2, &s3);
}
```
Output:
diff --git a/docs/cvec_api.md b/docs/cvec_api.md
index 92629c8b..08c404af 100644
--- a/docs/cvec_api.md
+++ b/docs/cvec_api.md
@@ -222,6 +222,6 @@ int main(void) {
c_FOREACH (i, UVec, vec2)
printf("%s: %d\n", cstr_str(&i.ref->name), i.ref->id);
- c_DROP(UVec, &vec, &vec2); // cleanup
+ c_drop(UVec, &vec, &vec2); // cleanup
}
``` \ No newline at end of file
diff --git a/include/stc/algo/crange.h b/include/stc/algo/crange.h
index 63242a54..5e1610d9 100644
--- a/include/stc/algo/crange.h
+++ b/include/stc/algo/crange.h
@@ -36,7 +36,7 @@ int main()
int a = 100, b = INT32_MAX;
c_FORFILTER (i, crange, crange_literal(a, b, 8)
, i.index > 10
- , c_FLT_TAKE(i, 3))
+ , c_flt_take(i, 3))
printf(" %lld", *i.ref);
puts("");
}
diff --git a/include/stc/algo/csort.h b/include/stc/algo/csort.h
index 2cd7b548..9c9bcd5b 100644
--- a/include/stc/algo/csort.h
+++ b/include/stc/algo/csort.h
@@ -84,13 +84,13 @@ static inline void c_PASTE(cqsort_, i_tag)(i_val arr[], intptr_t lo, intptr_t hi
while (i_less((&arr[i]), (&pivot))) ++i;
while (i_less((&pivot), (&arr[j]))) --j;
if (i <= j) {
- c_SWAP(i_val, arr+i, arr+j);
+ c_swap(i_val, arr+i, arr+j);
++i; --j;
}
}
if (j - lo > hi - i) {
- c_SWAP(intptr_t, &lo, &i);
- c_SWAP(intptr_t, &hi, &j);
+ c_swap(intptr_t, &lo, &i);
+ c_swap(intptr_t, &hi, &j);
}
if (j - lo > 64) c_PASTE(cqsort_, i_tag)(arr, lo, j);
diff --git a/include/stc/algo/filter.h b/include/stc/algo/filter.h
index e941be2e..0f850f41 100644
--- a/include/stc/algo/filter.h
+++ b/include/stc/algo/filter.h
@@ -37,9 +37,9 @@ int main()
puts("");
c_FORFILTER (i, cstack_int, stk
- , c_FLT_SKIPWHILE(i, *i.ref < 3)
+ , c_flt_skipwhile(i, *i.ref < 3)
&& (*i.ref & 1) == 0 // even only
- , c_FLT_TAKE(i, 2)) // break after 2
+ , c_flt_take(i, 2)) // break after 2
printf(" %d", *i.ref);
puts("");
}
@@ -54,10 +54,10 @@ int main()
#define c_NFILTERS 14 /* 22, 30, .. */
#endif
-#define c_FLT_TAKE(i, n) (++(i).s1[(i).s1top++] <= (n))
-#define c_FLT_SKIP(i, n) (++(i).s1[(i).s1top++] > (n))
-#define c_FLT_SKIPWHILE(i, pred) ((i).s2[(i).s2top++] |= !(pred))
-#define c_FLT_TAKEWHILE(i, pred) !c_FLT_SKIPWHILE(i, pred)
+#define c_flt_take(i, n) (++(i).s1[(i).s1top++] <= (n))
+#define c_flt_skip(i, n) (++(i).s1[(i).s1top++] > (n))
+#define c_flt_skipwhile(i, pred) ((i).s2[(i).s2top++] |= !(pred))
+#define c_flt_takewhile(i, pred) !c_flt_skipwhile(i, pred)
#define c_FORFILTER(...) c_MACRO_OVERLOAD(c_FORFILTER, __VA_ARGS__)
diff --git a/include/stc/carc.h b/include/stc/carc.h
index 614af18e..fa2ee3b4 100644
--- a/include/stc/carc.h
+++ b/include/stc/carc.h
@@ -45,7 +45,7 @@ int main() {
ArcPers q = ArcPers_clone(p); // share the pointer
printf("%s %s. uses: %ld\n", cstr_str(&q.get->name), cstr_str(&q.get->last), *q.use_count);
- c_DROP(ArcPers, &p, &q);
+ c_drop(ArcPers, &p, &q);
}
*/
#include "ccommon.h"
@@ -93,7 +93,7 @@ _cx_deftypes(_c_carc_types, _cx_self, i_key);
struct _cx_memb(_rep_) { catomic_long counter; i_key value; };
STC_INLINE _cx_self _cx_memb(_init)(void)
- { return c_INIT(_cx_self){NULL, NULL}; }
+ { return c_COMPOUND(_cx_self){NULL, NULL}; }
STC_INLINE long _cx_memb(_use_count)(const _cx_self* self)
{ return self->use_count ? *self->use_count : 0; }
diff --git a/include/stc/cbits.h b/include/stc/cbits.h
index 6a71487f..b0cb7a9c 100644
--- a/include/stc/cbits.h
+++ b/include/stc/cbits.h
@@ -123,7 +123,7 @@ STC_INLINE bool _cbits_disjoint(const uint64_t* set, const uint64_t* other, cons
struct { uint64_t *data64; size_t _size; } typedef i_type;
-STC_INLINE cbits cbits_init(void) { return c_INIT(cbits){NULL}; }
+STC_INLINE cbits cbits_init(void) { return c_COMPOUND(cbits){NULL}; }
STC_INLINE void cbits_create(cbits* self) { self->data64 = NULL; self->_size = 0; }
STC_INLINE void cbits_drop(cbits* self) { c_FREE(self->data64); }
STC_INLINE size_t cbits_size(const cbits* self) { return self->_size; }
@@ -195,7 +195,7 @@ STC_INLINE cbits cbits_with_pattern(const size_t size, const uint64_t pattern) {
struct { uint64_t data64[(i_capacity - 1)/64 + 1]; } typedef i_type;
-STC_INLINE i_type _i_memb(_init)(void) { return c_INIT(i_type){0}; }
+STC_INLINE i_type _i_memb(_init)(void) { return c_COMPOUND(i_type){0}; }
STC_INLINE void _i_memb(_create)(i_type* self) {}
STC_INLINE void _i_memb(_drop)(i_type* self) {}
STC_INLINE size_t _i_memb(_size)(const i_type* self) { return i_capacity; }
diff --git a/include/stc/cbox.h b/include/stc/cbox.h
index 95dfdf8f..6dc41ed1 100644
--- a/include/stc/cbox.h
+++ b/include/stc/cbox.h
@@ -37,7 +37,7 @@ Person Person_clone(Person p) {
}
void Person_drop(Person* p) {
printf("drop: %s %s\n", cstr_str(&p->name), cstr_str(&p->email));
- c_DROP(cstr, &p->name, &p->email);
+ c_drop(cstr, &p->name, &p->email);
}
#define i_keyclass Person // bind Person clone+drop fn's
@@ -79,13 +79,13 @@ _cx_deftypes(_c_cbox_types, _cx_self, i_key);
// constructors (take ownership)
STC_INLINE _cx_self _cx_memb(_init)(void)
- { return c_INIT(_cx_self){NULL}; }
+ { return c_COMPOUND(_cx_self){NULL}; }
STC_INLINE long _cx_memb(_use_count)(const _cx_self* self)
{ return (long)(self->get != NULL); }
STC_INLINE _cx_self _cx_memb(_from_ptr)(_cx_value* p)
- { return c_INIT(_cx_self){p}; }
+ { return c_COMPOUND(_cx_self){p}; }
// c++: std::make_unique<i_key>(val)
STC_INLINE _cx_self _cx_memb(_make)(_cx_value val) {
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index d7b68d1f..09befa56 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -71,12 +71,12 @@
#define c_ALLOC(T) static_cast<T*>(c_MALLOC(sizeof(T)))
#define c_ALLOC_N(T, n) static_cast<T*>(c_MALLOC(sizeof(T)*(n)))
#define c_NEW(T, ...) new (c_ALLOC(T)) T(__VA_ARGS__)
- #define c_INIT(T) T
+ #define c_COMPOUND(T) T
#else
#define c_ALLOC(T) ((T*)c_MALLOC(sizeof(T)))
#define c_ALLOC_N(T, n) ((T*)c_MALLOC(sizeof(T)*(n)))
#define c_NEW(T, ...) ((T*)memcpy(c_ALLOC(T), (T[]){__VA_ARGS__}, sizeof(T)))
- #define c_INIT(T) (T)
+ #define c_COMPOUND(T) (T)
#endif
#ifndef c_MALLOC
#define c_MALLOC(sz) malloc(sz)
@@ -85,12 +85,11 @@
#define c_FREE(p) free(p)
#endif
-#define c_STATIC_ASSERT(b) ((int)(0*sizeof(int[(b) ? 1 : -1])))
-#define c_CONTAINER_OF(p, T, m) ((T*)((char*)(p) + 0*sizeof((p) == &((T*)0)->m) - offsetof(T, m)))
-#define c_DELETE(T, ptr) do { T *_tp = ptr; T##_drop(_tp); c_FREE(_tp); } while (0)
-#define c_SWAP(T, xp, yp) do { T *_xp = xp, *_yp = yp, \
+#define c_static_assert(b) ((int)(0*sizeof(int[(b) ? 1 : -1])))
+#define c_container_of(p, T, m) ((T*)((char*)(p) + 0*sizeof((p) == &((T*)0)->m) - offsetof(T, m)))
+#define c_delete(T, ptr) do { T *_tp = ptr; T##_drop(_tp); c_FREE(_tp); } while (0)
+#define c_swap(T, xp, yp) do { T *_xp = xp, *_yp = yp, \
_tv = *_xp; *_xp = *_yp; *_yp = _tv; } while (0)
-#define c_ARRAYLEN(a) (sizeof(a)/sizeof 0[a])
// x and y are i_keyraw* type, defaults to i_key*:
#define c_default_cmp(x, y) (c_default_less(y, x) - c_default_less(x, y))
@@ -115,18 +114,18 @@
#define c_initialize(C, ...) \
C##_from_n((C##_raw[])__VA_ARGS__, sizeof((C##_raw[])__VA_ARGS__)/sizeof(C##_raw))
-#define c_literal(C, ...) (*(C[]){c_initialize(C, __VA_ARGS__)})
-/* Generic algorithms */
+/* Function macros and various others */
typedef const char* crawstr;
#define crawstr_cmp(xp, yp) strcmp(*(xp), *(yp))
#define crawstr_hash(p) cstrhash(*(p))
#define crawstr_len(literal) (sizeof("" literal) - 1U)
+#define c_ARRAYLEN(a) (sizeof(a)/sizeof 0[a])
#define c_SV(...) c_MACRO_OVERLOAD(c_SV, __VA_ARGS__)
#define c_SV1(lit) c_SV2(lit, crawstr_len(lit))
-#define c_SV2(str, n) (c_INIT(csview){str, n})
+#define c_SV2(str, n) (c_COMPOUND(csview){str, n})
#define c_ARGSV(sv) (int)(sv).size, (sv).str /* use with "%.*s" */
#define c_PAIR(ref) (ref)->first, (ref)->second
@@ -166,6 +165,8 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle,
return NULL;
}
+/* Control block macros */
+
#define c_FOREACH(...) c_MACRO_OVERLOAD(c_FOREACH, __VA_ARGS__)
#define c_FOREACH3(it, C, cnt) \
for (C##_iter it = C##_begin(&cnt); it.ref; C##_next(&it))
@@ -208,7 +209,6 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle,
#define c_WITH3(declvar, pred, drop) for (declvar, **_c_i = NULL; !_c_i && (pred); ++_c_i, drop)
#define c_SCOPE(init, drop) for (int _c_i = (init, 1); _c_i; --_c_i, drop)
#define c_DEFER(...) for (int _c_i = 1; _c_i; --_c_i, __VA_ARGS__)
-#define c_DROP(C, ...) do { c_FORLIST (_i, C*, {__VA_ARGS__}) C##_drop(*_i.ref); } while(0)
#define c_AUTO(...) c_MACRO_OVERLOAD(c_AUTO, __VA_ARGS__)
#define c_AUTO2(C, a) \
@@ -223,13 +223,16 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle,
c_WITH2(c_EXPAND(C a = C##_init(), b = C##_init(), c = C##_init(), d = C##_init()), \
(C##_drop(&d), C##_drop(&c), C##_drop(&b), C##_drop(&a)))
-#define c_FIND_IF(...) c_MACRO_OVERLOAD(c_FIND_IF, __VA_ARGS__)
-#define c_FIND_IF4(it, C, cnt, pred) do { \
+/* Generic functions */
+
+#define c_drop(C, ...) do { c_FORLIST (_i, C*, {__VA_ARGS__}) C##_drop(*_i.ref); } while(0)
+#define c_find_if(...) c_MACRO_OVERLOAD(c_find_if, __VA_ARGS__)
+#define c_find_if4(it, C, cnt, pred) do { \
size_t index = 0; \
for (it = C##_begin(&cnt); it.ref && !(pred); C##_next(&it)) \
++index; \
} while (0)
-#define c_FIND_IF5(it, C, start, end, pred) do { \
+#define c_find_if5(it, C, start, end, pred) do { \
size_t index = 0; \
const C##_value* _endref = (end).ref; \
for (it = start; it.ref != _endref && !(pred); C##_next(&it)) \
@@ -237,7 +240,7 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle,
if (it.ref == _endref) it.ref = NULL; \
} while (0)
-#define c_ERASE_IF(it, C, cnt, pred) do { \
+#define c_erase_if(it, C, cnt, pred) do { \
C##_iter it = C##_begin(&cnt); \
for (size_t index = 0; it.ref; ++index) { \
if (pred) it = C##_erase_at(&cnt, it); \
diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h
index b555da63..befb4146 100644
--- a/include/stc/cdeq.h
+++ b/include/stc/cdeq.h
@@ -101,11 +101,11 @@ STC_INLINE void _cx_memb(_pop_front)(_cx_self* self) // == _pop() when _
STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) {
size_t n = self->_len;
- return c_INIT(_cx_iter){n ? self->data : NULL, self->data + n};
+ return c_COMPOUND(_cx_iter){n ? self->data : NULL, self->data + n};
}
STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self)
- { return c_INIT(_cx_iter){NULL, self->data + self->_len}; }
+ { return c_COMPOUND(_cx_iter){NULL, self->data + self->_len}; }
STC_INLINE void _cx_memb(_next)(_cx_iter* it)
{ if (++it->ref == it->end) it->ref = NULL; }
@@ -345,7 +345,7 @@ _cx_memb(_insert_uninit)(_cx_self* self, _cx_value* pos, const size_t n) {
self->_len += n;
pos = self->data + idx;
}
- return c_INIT(_cx_iter){pos, self->data + self->_len};
+ return c_COMPOUND(_cx_iter){pos, self->data + self->_len};
}
STC_DEF _cx_value*
@@ -377,7 +377,7 @@ _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2) {
{ i_keydrop(p); }
memmove(p1, p2, (size_t)(end - p2)*sizeof *p1);
self->_len -= (size_t)len;
- return c_INIT(_cx_iter){p2 == end ? NULL : p1, end - len};
+ return c_COMPOUND(_cx_iter){p2 == end ? NULL : p1, end - len};
}
#if !defined i_no_clone
diff --git a/include/stc/clist.h b/include/stc/clist.h
index ac687fc9..de32b931 100644
--- a/include/stc/clist.h
+++ b/include/stc/clist.h
@@ -64,7 +64,7 @@
SELF##_value value; \
}
-#define _clist_tonode(vp) c_CONTAINER_OF(vp, _cx_node, value)
+#define _clist_tonode(vp) c_container_of(vp, _cx_node, value)
_c_clist_types(clist_VOID, int);
_c_clist_complete_types(clist_VOID, dummy);
@@ -133,7 +133,7 @@ STC_INLINE _cx_value* _cx_memb(_emplace)(_cx_self* self, _cx_raw raw)
{ return _cx_memb(_push_back)(self, i_keyfrom(raw)); }
#endif // !i_no_emplace
-STC_INLINE _cx_self _cx_memb(_init)(void) { return c_INIT(_cx_self){NULL}; }
+STC_INLINE _cx_self _cx_memb(_init)(void) { return c_COMPOUND(_cx_self){NULL}; }
STC_INLINE void _cx_memb(_put_n)(_cx_self* self, const _cx_raw* raw, size_t n)
{ while (n--) _cx_memb(_push_back)(self, i_keyfrom(*raw++)); }
STC_INLINE _cx_self _cx_memb(_from_n)(const _cx_raw* raw, size_t n)
@@ -161,12 +161,12 @@ _cx_memb(_count)(const _cx_self* self) {
STC_INLINE _cx_iter
_cx_memb(_begin)(const _cx_self* self) {
_cx_value* head = self->last ? &self->last->next->value : NULL;
- return c_INIT(_cx_iter){head, &self->last, self->last};
+ return c_COMPOUND(_cx_iter){head, &self->last, self->last};
}
STC_INLINE _cx_iter
_cx_memb(_end)(const _cx_self* self)
- { return c_INIT(_cx_iter){NULL}; }
+ { return c_COMPOUND(_cx_iter){NULL}; }
STC_INLINE void
_cx_memb(_next)(_cx_iter* it) {
diff --git a/include/stc/cmap.h b/include/stc/cmap.h
index e63adb77..c2f8cf3e 100644
--- a/include/stc/cmap.h
+++ b/include/stc/cmap.h
@@ -107,7 +107,7 @@ STC_API chash_bucket_t _cx_memb(_bucket_)(const _cx_self* self, const _cx_rawke
STC_API _cx_result _cx_memb(_insert_entry_)(_cx_self* self, _cx_rawkey rkey);
STC_API void _cx_memb(_erase_entry)(_cx_self* self, _cx_value* val);
-STC_INLINE _cx_self _cx_memb(_init)(void) { return c_INIT(_cx_self){0}; }
+STC_INLINE _cx_self _cx_memb(_init)(void) { return c_COMPOUND(_cx_self){0}; }
STC_INLINE void _cx_memb(_shrink_to_fit)(_cx_self* self) { _cx_memb(_reserve)(self, self->size); }
STC_INLINE float _cx_memb(_max_load_factor)(const _cx_self* self) { return (float)(i_max_load_factor); }
STC_INLINE bool _cx_memb(_empty)(const _cx_self* map) { return !map->size; }
@@ -166,7 +166,7 @@ _cx_memb(_emplace)(_cx_self* self, _cx_rawkey rkey _i_MAP_ONLY(, i_valraw rmappe
STC_INLINE _cx_raw
_cx_memb(_value_toraw)(const _cx_value* val) {
return _i_SET_ONLY( i_keyto(val) )
- _i_MAP_ONLY( c_INIT(_cx_raw){i_keyto((&val->first)), i_valto((&val->second))} );
+ _i_MAP_ONLY( c_COMPOUND(_cx_raw){i_keyto((&val->first)), i_valto((&val->second))} );
}
STC_INLINE void
@@ -222,7 +222,7 @@ STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) {
STC_INLINE _cx_iter
_cx_memb(_end)(const _cx_self* self)
- { return c_INIT(_cx_iter){NULL}; }
+ { return c_COMPOUND(_cx_iter){NULL}; }
STC_INLINE void
_cx_memb(_next)(_cx_iter* it) {
@@ -240,7 +240,7 @@ STC_INLINE _cx_iter
_cx_memb(_find)(const _cx_self* self, _cx_rawkey rkey) {
size_t idx;
if (self->size && self->_hashx[idx = _cx_memb(_bucket_)(self, &rkey).idx])
- return c_INIT(_cx_iter){self->table + idx,
+ return c_COMPOUND(_cx_iter){self->table + idx,
self->table + self->bucket_count,
self->_hashx + idx};
return _cx_memb(_end)(self);
@@ -430,7 +430,7 @@ _cx_memb(_reserve)(_cx_self* self, const size_t _newcap) {
m.table[b.idx] = *e;
m._hashx[b.idx] = (uint8_t)b.hx;
}
- c_SWAP(_cx_self, self, &m);
+ c_swap(_cx_self, self, &m);
}
c_FREE(m._hashx);
c_FREE(m.table);
diff --git a/include/stc/cpque.h b/include/stc/cpque.h
index f1f03f8e..83fcb684 100644
--- a/include/stc/cpque.h
+++ b/include/stc/cpque.h
@@ -45,7 +45,7 @@ STC_API void _cx_memb(_erase_at)(_cx_self* self, size_t idx);
STC_API void _cx_memb(_push)(_cx_self* self, _cx_value value);
STC_INLINE _cx_self _cx_memb(_init)(void)
- { return c_INIT(_cx_self){NULL}; }
+ { return c_COMPOUND(_cx_self){NULL}; }
STC_INLINE void _cx_memb(_put_n)(_cx_self* self, const _cx_raw* raw, size_t n)
{ while (n--) _cx_memb(_push)(self, i_keyfrom(*raw++)); }
diff --git a/include/stc/crandom.h b/include/stc/crandom.h
index 733c3ec5..9cb23e93 100644
--- a/include/stc/crandom.h
+++ b/include/stc/crandom.h
@@ -100,12 +100,12 @@ STC_INLINE double stc64_uniformf(stc64_t* rng, stc64_uniformf_t* dist) {
/* Init uniform distributed float64 RNG, range [low, high). */
STC_INLINE stc64_uniformf_t stc64_uniformf_new(double low, double high) {
- return c_INIT(stc64_uniformf_t){low, high - low};
+ return c_COMPOUND(stc64_uniformf_t){low, high - low};
}
/* Marsaglia polar method for gaussian/normal distribution, float64. */
STC_INLINE stc64_normalf_t stc64_normalf_new(double mean, double stddev) {
- return c_INIT(stc64_normalf_t){mean, stddev, 0.0, 0};
+ return c_COMPOUND(stc64_normalf_t){mean, stddev, 0.0, 0};
}
/* -------------------------- IMPLEMENTATION ------------------------- */
diff --git a/include/stc/csmap.h b/include/stc/csmap.h
index 75f10308..67b2265e 100644
--- a/include/stc/csmap.h
+++ b/include/stc/csmap.h
@@ -143,7 +143,7 @@ _cx_memb(_clear)(_cx_self* self)
STC_INLINE _cx_raw
_cx_memb(_value_toraw)(const _cx_value* val) {
return _i_SET_ONLY( i_keyto(val) )
- _i_MAP_ONLY( c_INIT(_cx_raw){i_keyto((&val->first)),
+ _i_MAP_ONLY( c_COMPOUND(_cx_raw){i_keyto((&val->first)),
i_valto((&val->second))} );
}
@@ -231,7 +231,7 @@ _cx_memb(_reserve)(_cx_self* self, const size_t cap) {
_cx_node* nodes = (_cx_node*)c_REALLOC(self->nodes, (cap + 1)*sizeof(_cx_node));
if (!nodes)
return false;
- nodes[0] = c_INIT(_cx_node){{0, 0}, 0};
+ nodes[0] = c_COMPOUND(_cx_node){{0, 0}, 0};
self->nodes = nodes;
self->cap = (i_size)cap;
return true;
diff --git a/include/stc/cspan.h b/include/stc/cspan.h
index 9969a670..88e10b07 100644
--- a/include/stc/cspan.h
+++ b/include/stc/cspan.h
@@ -40,18 +40,17 @@ int demo1() {
}
int demo2() {
- int array[] = {1, 2, 3, 4, 5};
+ int array[] = {10, 20, 30, 23, 22, 21};
Intspan span = cspan_from_array(array);
c_FOREACH (i, Intspan, span)
printf(" %d", *i.ref);
puts("");
- // use a temporary Intspan object.
- c_FORFILTER (i, Intspan, c_literal(Intspan, {10, 20, 30, 23, 22, 21})
- , c_FLT_SKIPWHILE(i, *i.ref < 25)
+ c_FORFILTER (i, Intspan, span,
+ , c_flt_skipwhile(i, *i.ref < 25)
&& (*i.ref & 1) == 0 // even only
- , c_FLT_TAKE(i, 2)) // break after 2
+ , c_flt_take(i, 2)) // break after 2
printf(" %d", *i.ref);
puts("");
}
@@ -86,7 +85,7 @@ int demo2() {
#define using_cspan3(Self, T) using_cspan2(Self, T); using_cspan(Self##3, T, 3)
#define using_cspan4(Self, T) using_cspan3(Self, T); using_cspan(Self##4, T, 4)
-#define cspan_rank_ok(self, rank) c_STATIC_ASSERT(cspan_rank(self) == rank)
+#define cspan_rank_ok(self, rank) c_static_assert(cspan_rank(self) == rank)
#define cspan_make(array, ...) \
{.data=array, .dim={__VA_ARGS__}}
@@ -96,7 +95,7 @@ int demo2() {
{.data=(container)->data, .dim={(uint32_t)(container)->_len}}
#define cspan_from_array(array) \
- {.data=(array) + c_STATIC_ASSERT(sizeof(array) != sizeof(void*)), .dim={c_ARRAYLEN(array)}}
+ {.data=(array) + c_static_assert(sizeof(array) != sizeof(void*)), .dim={c_ARRAYLEN(array)}}
#define cspan_size(self) _cspan_size((self)->dim, cspan_rank(self))
#define cspan_rank(self) c_ARRAYLEN((self)->dim)
diff --git a/include/stc/cstack.h b/include/stc/cstack.h
index c1332769..a40b74de 100644
--- a/include/stc/cstack.h
+++ b/include/stc/cstack.h
@@ -175,12 +175,12 @@ STC_INLINE i_keyraw _cx_memb(_value_toraw)(const _cx_value* val)
#endif // !i_no_clone
STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) {
- return c_INIT(_cx_iter){self->_len ? (_cx_value*)self->data : NULL,
+ return c_COMPOUND(_cx_iter){self->_len ? (_cx_value*)self->data : NULL,
(_cx_value*)self->data + self->_len};
}
STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self)
- { return c_INIT(_cx_iter){NULL, (_cx_value*)self->data + self->_len}; }
+ { return c_COMPOUND(_cx_iter){NULL, (_cx_value*)self->data + self->_len}; }
STC_INLINE void _cx_memb(_next)(_cx_iter* it)
{ if (++it->ref == it->end) it->ref = NULL; }
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index 46ad2fcd..b500065e 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -71,7 +71,7 @@ STC_API char* _cstr_internal_move(cstr* self, size_t pos1, size_t pos2);
/**************************** PUBLIC API **********************************/
#define cstr_lit(literal) cstr_from_n(literal, crawstr_len(literal))
-#define cstr_NULL (c_INIT(cstr){{{0}, 0}})
+#define cstr_NULL (c_COMPOUND(cstr){{{0}, 0}})
#define cstr_toraw(self) cstr_str(self)
STC_API char* cstr_reserve(cstr* self, size_t cap);
@@ -90,12 +90,12 @@ STC_API cstr cstr_replace_sv(csview sv, csview search, csview repl, unsigned
STC_INLINE cstr_buf cstr_buffer(cstr* s) {
return cstr_is_long(s)
- ? c_INIT(cstr_buf){s->lon.data, cstr_l_size(s), cstr_l_cap(s)}
- : c_INIT(cstr_buf){s->sml.data, cstr_s_size(s), cstr_s_cap};
+ ? c_COMPOUND(cstr_buf){s->lon.data, cstr_l_size(s), cstr_l_cap(s)}
+ : c_COMPOUND(cstr_buf){s->sml.data, cstr_s_size(s), cstr_s_cap};
}
STC_INLINE csview cstr_sv(const cstr* s) {
- return cstr_is_long(s) ? c_INIT(csview){s->lon.data, cstr_l_size(s)}
- : c_INIT(csview){s->sml.data, cstr_s_size(s)};
+ return cstr_is_long(s) ? c_COMPOUND(csview){s->lon.data, cstr_l_size(s)}
+ : c_COMPOUND(csview){s->sml.data, cstr_s_size(s)};
}
STC_INLINE cstr cstr_init(void)
@@ -222,11 +222,11 @@ STC_INLINE csview cstr_u8_chr(const cstr* self, size_t u8idx) {
STC_INLINE cstr_iter cstr_begin(const cstr* self) {
csview sv = cstr_sv(self);
- if (!sv.size) return c_INIT(cstr_iter){NULL};
- return c_INIT(cstr_iter){.u8 = {{sv.str, utf8_chr_size(sv.str)}}};
+ if (!sv.size) return c_COMPOUND(cstr_iter){NULL};
+ return c_COMPOUND(cstr_iter){.u8 = {{sv.str, utf8_chr_size(sv.str)}}};
}
STC_INLINE cstr_iter cstr_end(const cstr* self) {
- (void)self; return c_INIT(cstr_iter){NULL};
+ (void)self; return c_COMPOUND(cstr_iter){NULL};
}
STC_INLINE void cstr_next(cstr_iter* it) {
it->ref += it->u8.chr.size;
diff --git a/include/stc/csview.h b/include/stc/csview.h
index 1ab34d9a..fb860a66 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -37,7 +37,7 @@
STC_API size_t csview_find_sv(csview sv, csview search);
STC_INLINE csview csview_from(const char* str)
- { return c_INIT(csview){str, strlen(str)}; }
+ { return c_COMPOUND(csview){str, strlen(str)}; }
STC_INLINE void csview_clear(csview* self) { *self = csview_NULL; }
STC_INLINE size_t csview_size(csview sv) { return sv.size; }
@@ -76,12 +76,12 @@ STC_INLINE csview csview_slice(csview sv, size_t p1, size_t p2) {
/* utf8 iterator */
STC_INLINE csview_iter csview_begin(const csview* self) {
- if (!self->size) return c_INIT(csview_iter){NULL};
- return c_INIT(csview_iter){.u8 = {{self->str, utf8_chr_size(self->str)},
- self->str + self->size}};
+ if (!self->size) return c_COMPOUND(csview_iter){NULL};
+ return c_COMPOUND(csview_iter){.u8 = {{self->str, utf8_chr_size(self->str)},
+ self->str + self->size}};
}
STC_INLINE csview_iter csview_end(const csview* self) {
- return c_INIT(csview_iter){.u8 = {{NULL}, self->str + self->size}};
+ return c_COMPOUND(csview_iter){.u8 = {{NULL}, self->str + self->size}};
}
STC_INLINE void csview_next(csview_iter* it) {
it->ref += it->u8.chr.size;
diff --git a/include/stc/cvec.h b/include/stc/cvec.h
index 7f8365d7..8010aea3 100644
--- a/include/stc/cvec.h
+++ b/include/stc/cvec.h
@@ -199,11 +199,11 @@ _cx_memb(_at_mut)(_cx_self* self, const size_t idx) {
STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) {
size_t n = self->_len;
- return c_INIT(_cx_iter){n ? self->data : NULL, self->data + n};
+ return c_COMPOUND(_cx_iter){n ? self->data : NULL, self->data + n};
}
STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self)
- { return c_INIT(_cx_iter){NULL, self->data + self->_len}; }
+ { return c_COMPOUND(_cx_iter){NULL, self->data + self->_len}; }
STC_INLINE void _cx_memb(_next)(_cx_iter* it)
{ if (++it->ref == it->end) it->ref = NULL; }
@@ -259,7 +259,7 @@ _cx_memb(_sort)(_cx_self* self) {
STC_DEF _cx_self
_cx_memb(_init)(void) {
- return c_INIT(_cx_self){NULL};
+ return c_COMPOUND(_cx_self){NULL};
}
STC_DEF void
@@ -328,7 +328,7 @@ _cx_memb(_insert_uninit)(_cx_self* self, _cx_value* pos, const size_t n) {
memmove(pos + n, pos, (self->_len - idx)*sizeof *pos);
self->_len += n;
}
- return c_INIT(_cx_iter){pos, self->data + self->_len};
+ return c_COMPOUND(_cx_iter){pos, self->data + self->_len};
}
STC_DEF _cx_iter
@@ -348,7 +348,7 @@ _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2) {
{ i_keydrop(p); }
memmove(p1, p2, (size_t)(end - p2)*sizeof *p1);
self->_len -= len;
- return c_INIT(_cx_iter){p2 == end ? NULL : p1, end - len};
+ return c_COMPOUND(_cx_iter){p2 == end ? NULL : p1, end - len};
}
#if !defined i_no_clone
diff --git a/include/stc/priv/lowcase.h b/include/stc/priv/lowcase.h
index 8fdadd75..cb6ed991 100644
--- a/include/stc/priv/lowcase.h
+++ b/include/stc/priv/lowcase.h
@@ -27,10 +27,6 @@
#define c_calloc c_CALLOC
#define c_realloc c_REALLOC
#define c_free c_FREE
-#define c_delete c_DELETE
-#define c_swap c_SWAP
-#define c_container_of c_CONTAINER_OF
-#define c_static_assert c_STATIC_ASSERT
#define c_arraylen c_ARRAYLEN
#define c_forlist c_FORLIST
#define c_forrange c_FORRANGE
@@ -45,14 +41,16 @@
#define c_with c_WITH
#define c_scope c_SCOPE
#define c_defer c_DEFER
-#define c_drop c_DROP
#define c_sv c_SV
-#define c_ARGsv c_ARGSV
-#define c_find_if c_FIND_IF
-#define c_erase_if c_ERASE_IF
-#define c_flt_take c_FLT_TAKE
-#define c_flt_skip c_FLT_SKIP
-#define c_flt_skipwhile c_FLT_SKIPWHILE
-#define c_flt_takewhile c_FLT_TAKEWHILE
-#define cstr_new(lit) cstr_lit(lit)
-#define cstr_null cstr_NULL
+
+#define c_DROP c_drop
+#define c_FIND_IF c_find_if
+#define c_ERASE_IF c_erase_if
+#define c_FLT_TAKE c_flt_take
+#define c_FLT_SKIP c_flt_skip
+#define c_FLT_SKIPWHILE c_flt_skipwhile
+#define c_FLT_TAKEWHILE c_flt_takewhile
+#define c_DELETE c_delete
+#define c_SWAP c_swap
+#define c_CONTAINER_OF c_container_of
+#define c_STATIC_ASSERT c_static_assert
diff --git a/misc/archived/csmap.h b/misc/archived/csmap.h
index 5c9fba6b..2daec3b9 100644
--- a/misc/archived/csmap.h
+++ b/misc/archived/csmap.h
@@ -129,8 +129,8 @@ _cx_memb(_clear)(_cx_self* self)
STC_INLINE _cx_raw
_cx_memb(_value_toraw)(_cx_value* val) {
return _i_SET_ONLY( i_keyto(val) )
- _i_MAP_ONLY( c_INIT(_cx_raw){i_keyto((&val->first)),
- i_valto((&val->second))} );
+ _i_MAP_ONLY( c_COMPOUND(_cx_raw){i_keyto((&val->first)),
+ i_valto((&val->second))} );
}
STC_INLINE int
@@ -470,7 +470,7 @@ _cx_memb(_clone_r_)(_cx_node *tn) {
STC_DEF _cx_self
_cx_memb(_clone)(_cx_self cx) {
- return c_INIT(_cx_self){_cx_memb(_clone_r_)(cx.root), cx.size};
+ return c_COMPOUND(_cx_self){_cx_memb(_clone_r_)(cx.root), cx.size};
}
#endif // !i_no_clone
diff --git a/misc/archived/cstr.h b/misc/archived/cstr.h
index e074b6e4..1a5b0da4 100644
--- a/misc/archived/cstr.h
+++ b/misc/archived/cstr.h
@@ -67,7 +67,7 @@ STC_INLINE cstr cstr_init() { return cstr_NULL; }
STC_INLINE const char* cstr_str(const cstr* self) { return self->str; }
#define cstr_toraw(self) (self)->str
STC_INLINE csview cstr_sv(const cstr* self)
- { return c_INIT(csview){self->str, _cstr_p(self)->size}; }
+ { return c_COMPOUND(csview){self->str, _cstr_p(self)->size}; }
#define cstr_lit(literal) \
cstr_from_n(literal, crawstr_len(literal))
STC_INLINE cstr cstr_from(const char* str)
@@ -118,7 +118,7 @@ STC_INLINE bool cstr_getline(cstr *self, FILE *stream)
STC_INLINE cstr_buf cstr_buffer(cstr* s) {
cstr_priv* p = _cstr_p(s);
- return c_INIT(cstr_buf){s->str, p->size, p->cap};
+ return c_COMPOUND(cstr_buf){s->str, p->size, p->cap};
}
STC_INLINE cstr cstr_with_capacity(const size_t cap) {
diff --git a/misc/examples/box.c b/misc/examples/box.c
index 446a7603..3a7a8139 100644
--- a/misc/examples/box.c
+++ b/misc/examples/box.c
@@ -24,7 +24,7 @@ Person Person_clone(Person p) {
void Person_drop(Person* p) {
printf("drop: %s %s\n", cstr_str(&p->name), cstr_str(&p->last));
- c_DROP(cstr, &p->name, &p->last);
+ c_drop(cstr, &p->name, &p->last);
}
#define i_type PBox
diff --git a/misc/examples/city.c b/misc/examples/city.c
index 7f355bdf..e24c90de 100644
--- a/misc/examples/city.c
+++ b/misc/examples/city.c
@@ -44,7 +44,7 @@ City City_clone(City c) {
void City_drop(City* c) {
printf("drop %s\n", cstr_str(&c->name));
- c_DROP(cstr, &c->name, &c->country);
+ c_drop(cstr, &c->name, &c->country);
}
diff --git a/misc/examples/forfilter.c b/misc/examples/forfilter.c
index 05d0bc28..e041fd68 100644
--- a/misc/examples/forfilter.c
+++ b/misc/examples/forfilter.c
@@ -33,12 +33,12 @@ void demo1(void)
int res, sum = 0;
c_FORFILTER (i, IVec, vec
- , c_FLT_SKIPWHILE(i, *i.ref != 80)
- && c_FLT_SKIP(i, 1)
- && c_FLT_SKIPWHILE(i, *i.ref != 80)
+ , c_flt_skipwhile(i, *i.ref != 80)
+ && c_flt_skip(i, 1)
+ && c_flt_skipwhile(i, *i.ref != 80)
&& flt_isEven(i)
&& flt_skipValue(i, 80)
- , c_FLT_TAKE(i, 5) // short-circuit
+ , c_flt_take(i, 5) // short-circuit
){
sum += res = flt_square(i);
printf(" %d", res);
@@ -66,9 +66,9 @@ void demo2(void)
puts("demo2:");
c_FORFILTER (x, crange, crange_literal(INT64_MAX)
- , c_FLT_SKIPWHILE(x, *x.ref != 11)
+ , c_flt_skipwhile(x, *x.ref != 11)
&& *x.ref % 2 != 0
- , c_FLT_TAKE(x, 5))
+ , c_flt_take(x, 5))
IVec_push(&vector, *x.ref * *x.ref);
c_FOREACH (x, IVec, vector)
printf(" %d", *x.ref);
@@ -128,11 +128,11 @@ void demo5(void)
puts("demo5:");
crange r1 = crange_make(1963, INT32_MAX);
c_FORFILTER (i, crange, r1
- , c_FLT_SKIP(i,15)
- && c_FLT_SKIPWHILE(i, flt_mid_decade(i))
- && c_FLT_SKIP(i,30)
+ , c_flt_skip(i,15)
+ && c_flt_skipwhile(i, flt_mid_decade(i))
+ && c_flt_skip(i,30)
&& flt_even(i)
- , c_FLT_TAKE(i,10))
+ , c_flt_take(i,10))
printf(" %lld", *i.ref);
puts("");
}
diff --git a/misc/examples/forloops.c b/misc/examples/forloops.c
index 69c1c193..cd3c4d9e 100644
--- a/misc/examples/forloops.c
+++ b/misc/examples/forloops.c
@@ -68,12 +68,12 @@ int main()
puts("\n\nc_forfilter:");
c_FORFILTER (i, IVec, vec
- , c_FLT_SKIPWHILE(i, *i.ref != 65)
- && c_FLT_TAKEWHILE(i, *i.ref != 280)
- && c_FLT_SKIPWHILE(i, isOdd(i))
+ , c_flt_skipwhile(i, *i.ref != 65)
+ && c_flt_takewhile(i, *i.ref != 280)
+ && c_flt_skipwhile(i, isOdd(i))
&& isOdd(i)
- && c_FLT_SKIP(i, 2)
- , c_FLT_TAKE(i, 1))
+ && c_flt_skip(i, 2)
+ , c_flt_take(i, 1))
printf(" %d", *i.ref);
puts("");
// 189
diff --git a/misc/examples/functor.c b/misc/examples/functor.c
index 54e2702d..f1db3644 100644
--- a/misc/examples/functor.c
+++ b/misc/examples/functor.c
@@ -23,7 +23,7 @@ struct {
#define i_type ipque
#define i_val int
#define i_opt c_is_forward // needed to avoid re-type-define container type
-#define i_less_functor(self, x, y) c_CONTAINER_OF(self, IPQueue, Q)->less(x, y)
+#define i_less_functor(self, x, y) c_container_of(self, IPQueue, Q)->less(x, y)
#include <stc/cpque.h>
void print_queue(const char* name, IPQueue q) {
diff --git a/misc/examples/music_arc.c b/misc/examples/music_arc.c
index 9896c591..fad7ddcf 100644
--- a/misc/examples/music_arc.c
+++ b/misc/examples/music_arc.c
@@ -16,7 +16,7 @@ Song Song_make(const char* artist, const char* title)
void Song_drop(Song* s) {
printf("drop: %s\n", cstr_str(&s->title));
- c_DROP(cstr, &s->artist, &s->title);
+ c_drop(cstr, &s->artist, &s->title);
}
// Define the reference counted type
diff --git a/misc/examples/new_sptr.c b/misc/examples/new_sptr.c
index 5441ae01..116827a4 100644
--- a/misc/examples/new_sptr.c
+++ b/misc/examples/new_sptr.c
@@ -43,7 +43,7 @@ Person Person_clone(Person p) {
}
void Person_drop(Person* p) {
printf("drop: %s %s\n", cstr_str(&p->name), cstr_str(&p->last));
- c_DROP(cstr, &p->name, &p->last);
+ c_drop(cstr, &p->name, &p->last);
}
diff --git a/misc/examples/person_arc.c b/misc/examples/person_arc.c
index f782c9da..4d9c2a51 100644
--- a/misc/examples/person_arc.c
+++ b/misc/examples/person_arc.c
@@ -24,7 +24,7 @@ Person Person_clone(Person p) {
void Person_drop(Person* p) {
printf("drop: %s %s\n", cstr_str(&p->name), cstr_str(&p->last));
- c_DROP(cstr, &p->name, &p->last);
+ c_drop(cstr, &p->name, &p->last);
}
#define i_type PSPtr
diff --git a/misc/examples/prime.c b/misc/examples/prime.c
index 40ccc299..4a6b0f68 100644
--- a/misc/examples/prime.c
+++ b/misc/examples/prime.c
@@ -45,7 +45,7 @@ int main(void)
puts("Show the last 50 primes using a temporary crange generator:");
c_FORFILTER (i, crange, crange_literal(n - 1, 0, -2)
, cbits_test(&primes, *i.ref>>1)
- , c_FLT_TAKE(i, 50)) {
+ , c_flt_take(i, 50)) {
printf("%lld ", *i.ref);
if (i.count % 10 == 0) puts("");
}
diff --git a/misc/examples/sso_substr.c b/misc/examples/sso_substr.c
index 8e7450ba..be372a8d 100644
--- a/misc/examples/sso_substr.c
+++ b/misc/examples/sso_substr.c
@@ -16,5 +16,5 @@ int main ()
cstr s3 = cstr_from_sv(cstr_substr_ex(&str, 0, 6)); // "apples"
printf("%s %s: %d, %d\n", cstr_str(&s2), cstr_str(&s3),
cstr_is_long(&str), cstr_is_long(&s2));
- c_DROP (cstr, &str, &s2, &s3);
+ c_drop (cstr, &str, &s2, &s3);
}
diff --git a/misc/examples/vikings.c b/misc/examples/vikings.c
index c65a9caa..a050b324 100644
--- a/misc/examples/vikings.c
+++ b/misc/examples/vikings.c
@@ -23,11 +23,11 @@ static inline int RViking_cmp(const RViking* rx, const RViking* ry) {
}
static inline Viking Viking_from(RViking raw) { // note: parameter is by value
- return c_INIT(Viking){cstr_from(raw.name), cstr_from(raw.country)};
+ return c_COMPOUND(Viking){cstr_from(raw.name), cstr_from(raw.country)};
}
static inline RViking Viking_toraw(const Viking* vp) {
- return c_INIT(RViking){cstr_str(&vp->name), cstr_str(&vp->country)};
+ return c_COMPOUND(RViking){cstr_str(&vp->name), cstr_str(&vp->country)};
}
// With this in place, we define the Viking => int hash map type: