diff options
| author | tylov <[email protected]> | 2023-08-11 22:43:59 +0200 |
|---|---|---|
| committer | tylov <[email protected]> | 2023-08-11 22:43:59 +0200 |
| commit | 31ba4b2a36dee10b7e5d58561a2c0291cff6faeb (patch) | |
| tree | 28c56e41c5d3534dc12821d407f4ff808b766cac | |
| parent | 0c29a8413619870f23682b74c032137e81db17e2 (diff) | |
| download | STC-modified-31ba4b2a36dee10b7e5d58561a2c0291cff6faeb.tar.gz STC-modified-31ba4b2a36dee10b7e5d58561a2c0291cff6faeb.zip | |
Finalized converting to i_use_cmp (vs i_no_cmp)
| -rw-r--r-- | README.md | 10 | ||||
| -rw-r--r-- | docs/cbox_api.md | 2 | ||||
| -rw-r--r-- | include/stc/carc.h | 9 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 3 | ||||
| -rw-r--r-- | misc/examples/smartpointers/arc_containers.c | 2 |
5 files changed, 13 insertions, 13 deletions
@@ -215,7 +215,6 @@ Let's make a vector of vectors, which can be cloned. All of its element vectors #define i_type Vec2D #define i_keyclass Vec // Use i_keyclass instead i_key when element type has "members" _clone(), _drop() and _cmp(). -#define i_opt c_no_cmp // Disable cmp (search/sort) for Vec2D because Vec_cmp() does not exist. #include <stc/cvec.h> int main(void) @@ -370,14 +369,14 @@ The list of template parameters: - `i_key` *Type* - Element key type. **[required]**. Note: `i_val` *may* be used instead for non-maps (not recommended). - `i_val` *Type* - Element value type. **[required for]** cmap/csmap as the mapped value type. -- `i_cmp` *Func* - Three-way comparison of two *i_keyraw*\* or *i_valraw*\* - **[required for]** non-integral *i_keyraw* elements unless *i_opt* is defined with *c_no_cmp*. +- `i_cmp` *Func* - Three-way comparison of two *i_keyraw*\* or *i_valraw*\* - **[required for]** non-integral *i_keyraw* elements. - `i_hash` *Func* - Hash function taking *i_keyraw*\* - defaults to *c_default_hash*. **[required for]** ***cmap/cset*** with non-POD *i_keyraw* elements. - `i_eq` *Func* - Equality comparison of two *i_keyraw*\* - defaults to *!i_cmp*. Companion with *i_hash*. Properties: - `i_tag` *Name* - Container type name tag. Defaults to *i_key* name. - `i_type` *Name* - Full container type name. Alternative to *i_tag*. -- `i_opt` *Flags* - Boolean properties: may combine *c_no_cmp*, *c_no_clone*, *c_no_atomic*, *c_is_forward*, *c_static*, *c_header* with the *|* separator. +- `i_opt` *Flags* - Boolean properties: may combine *c_no_clone*, *c_no_atomic*, *c_is_forward*, *c_static*, *c_header* with the *|* separator. Key: - `i_keydrop` *Func* - Destroy map/set key func - defaults to empty destructor. @@ -398,7 +397,7 @@ Specials: Meta-template parameters. Use instead of `i_key` / `i_val`. If `i_keyraw` is defined, it sets `i_keyto` = *Type_toraw()* and `i_keyfrom` = *Type_from()*. Only functions required by the container type is required to be defined. E.g.: - *Type_hash()* and *Type_eq()* are only required by **cmap**, **cset** and smart pointers. - - *Type_cmp()* is not used by **cstack** and **cmap/cset**, or if *#define i_opt c_no_cmp* is specified. + - *Type_cmp()* is not used by **cstack** and **cmap/cset**. - *Type_clone()* is not used if *#define i_opt c_no_clone* is specified. - `i_key_str` - Sets `i_keyclass` = *cstr*, `i_tag` = *str*, and `i_keyraw` = *const char*\*. Defines both type convertion `i_keyfrom`, `i_keyto`, and sets `i_cmp`, `i_eq`, `i_hash` functions with *const char\*\** as argument. @@ -409,7 +408,6 @@ NB: Do not use when defining carc/cbox types themselves. - `i_valclass` *Type*, `i_val_str`, `i_val_ssv`, `i_valboxed` - Similar rules as for ***key***. **Notes**: -- Instead of defining `i_cmp`, you may define *i_opt c_no_cmp* to disable *searching and sorting* functions. - Instead of defining `i_*clone`, you may define *i_opt c_no_clone* to disable *clone* functionality. - For `i_keyclass`, if *i_keyraw* is defined along with it, *i_keyfrom* may also be defined to enable the *emplace*-functions. NB: the signature for ***cmp***, ***eq***, and ***hash*** uses *i_keyraw* as input. @@ -764,6 +762,6 @@ Major changes: - Replaced: *csview_first_token()* and *csview_next_token()* with one function: `csview_token()`. - Added: **checkauto** tool for checking that c-source files uses `c_auto*` macros correctly. - Added: general `i_keyclass` / `i_valclass` template parameters which auto-binds template functions. -- Added: `i_opt` template parameter: compile-time options: `c_no_cmp`, `c_no_clone`, `c_no_atomic`, `c_is_forward`; may be combined with `|` +- Added: `i_opt` template parameter: compile-time options: `c_no_clone`, `c_no_atomic`, `c_is_forward`; may be combined with `|` - Added: [**cbox**](docs/cbox_api.md) type: smart pointer, similar to [Rust Box](https://doc.rust-lang.org/rust-by-example/std/box.html) and [std::unique_ptr](https://en.cppreference.com/w/cpp/memory/unique_ptr). - Added: [**c_forpair**](docs/algorithm_api.md) macro: for-loop with "structured binding" diff --git a/docs/cbox_api.md b/docs/cbox_api.md index c683d9ef..7d25aed8 100644 --- a/docs/cbox_api.md +++ b/docs/cbox_api.md @@ -34,7 +34,7 @@ See similar c++ class [std::unique_ptr](https://en.cppreference.com/w/cpp/memory #include <stc/cbox.h> ``` `X` should be replaced by the value of `i_tag` in all of the following documentation. -Define `i_opt` with `c_no_cmp` if comparison between i_key's is not needed/available. Will then +Unless `c_use_cmp` is defined, comparison between i_key's is not needed/available. Will then compare the pointer addresses when used. Additionally, `c_no_clone` or `i_is_fwd` may be defined. ## Methods diff --git a/include/stc/carc.h b/include/stc/carc.h index e987f453..1b1c22eb 100644 --- a/include/stc/carc.h +++ b/include/stc/carc.h @@ -43,7 +43,6 @@ void Person_drop(Person* p) { #define i_type ArcPers #define i_valclass Person // clone, drop, cmp, hash -#define i_opt c_no_cmp|c_no_hash // exclude cmp, hash #include <stc/carc.h> int main(void) { @@ -86,7 +85,10 @@ int main(void) { #include "priv/template.h" typedef i_keyraw _cx_raw; -#if !c_option(c_no_atomic) +#if c_option(c_no_atomic) + #define i_no_atomic +#endif +#if !defined i_no_atomic #define _i_atomic_inc(v) c_atomic_inc(v) #define _i_atomic_dec_and_test(v) c_atomic_dec_and_test(v) #else @@ -213,7 +215,8 @@ STC_INLINE void _cx_MEMB(_assign)(_cx_Self* self, _cx_Self ptr) { { return c_default_hash(&self->get); } #endif // i_use_cmp +#include "priv/template2.h" +#undef i_no_atomic #undef _i_atomic_inc #undef _i_atomic_dec_and_test -#include "priv/template2.h" #undef _i_carc diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index b37ad1da..45fa01c6 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -116,9 +116,8 @@ typedef long long _llong; #define c_no_atomic (1<<1) #define c_no_clone (1<<2) #define c_no_emplace (1<<3) -#define c_no_cmp (1<<4) +#define c_no_hash (1<<4) #define c_use_cmp (1<<5) -#define c_no_hash (1<<6) /* Function macros and others */ #define c_litstrlen(literal) (c_sizeof("" literal) - 1) diff --git a/misc/examples/smartpointers/arc_containers.c b/misc/examples/smartpointers/arc_containers.c index c2bff56f..79211d2b 100644 --- a/misc/examples/smartpointers/arc_containers.c +++ b/misc/examples/smartpointers/arc_containers.c @@ -12,7 +12,7 @@ #define i_key Map #define i_keydrop(p) (printf("drop Arc:\n"), Map_drop(p)) // no need for atomic ref. count in single thread: -#define i_opt c_no_atomic|c_no_cmp +#define i_opt c_no_atomic #include <stc/carc.h> #define i_type Stack |
