summaryrefslogtreecommitdiffhomepage
path: root/include/stc/priv/template.h
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-07-18 02:36:04 +0200
committerGitHub <[email protected]>2023-07-18 02:36:04 +0200
commitda70303c149b37dbf442e41038a00836132562ee (patch)
tree06d795c66d6759e06de5f2d166215b461ac40d1d /include/stc/priv/template.h
parent071b41c0fe95cb3f9a72bbe0417d856e7989ca08 (diff)
parent23eeedb3fc298602732f394adba6a43c876ca7d8 (diff)
downloadSTC-modified-da70303c149b37dbf442e41038a00836132562ee.tar.gz
STC-modified-da70303c149b37dbf442e41038a00836132562ee.zip
Merge branch 'dev43' into master
Diffstat (limited to 'include/stc/priv/template.h')
-rw-r--r--include/stc/priv/template.h127
1 files changed, 72 insertions, 55 deletions
diff --git a/include/stc/priv/template.h b/include/stc/priv/template.h
index 16ef51af..30ed5732 100644
--- a/include/stc/priv/template.h
+++ b/include/stc/priv/template.h
@@ -20,34 +20,28 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#ifdef _i_template
- #error template.h already included
-#endif
+#ifndef _i_template
#define _i_template
#ifndef STC_TEMPLATE_H_INCLUDED
#define STC_TEMPLATE_H_INCLUDED
- #define _cx_self i_type
- #define _cx_memb(name) c_PASTE(_cx_self, name)
- #define _cx_deftypes(macro, SELF, ...) c_EXPAND(macro(SELF, __VA_ARGS__))
- #define _cx_value _cx_memb(_value)
- #define _cx_key _cx_memb(_key)
- #define _cx_mapped _cx_memb(_mapped)
- #define _cx_raw _cx_memb(_raw)
- #define _cx_keyraw _cx_memb(_keyraw)
- #define _cx_iter _cx_memb(_iter)
- #define _cx_result _cx_memb(_result)
- #define _cx_node _cx_memb(_node)
+ #define _cx_Self i_type
+ #define _cx_MEMB(name) c_PASTE(_cx_Self, name)
+ #define _cx_DEFTYPES(macro, SELF, ...) c_EXPAND(macro(SELF, __VA_ARGS__))
+ #define _cx_value _cx_MEMB(_value)
+ #define _cx_key _cx_MEMB(_key)
+ #define _cx_mapped _cx_MEMB(_mapped)
+ #define _cx_raw _cx_MEMB(_raw)
+ #define _cx_keyraw _cx_MEMB(_keyraw)
+ #define _cx_iter _cx_MEMB(_iter)
+ #define _cx_result _cx_MEMB(_result)
+ #define _cx_node _cx_MEMB(_node)
#endif
#ifndef i_type
#define i_type c_PASTE(_i_prefix, i_tag)
#endif
-#ifndef i_ssize
- #define i_ssize intptr_t
-#endif
-
#ifndef i_allocator
#define i_allocator c
#endif
@@ -108,14 +102,16 @@
#if c_option(c_no_emplace)
#define i_no_emplace
#endif
-#ifdef i_eq
- #define _i_has_eq
+#if c_option(c_native_cmp)
+ #define i_native_cmp
+#endif
+#if c_option(c_no_clone) || defined _i_carc
+ #define i_no_clone
#endif
#if defined i_key_str
#define i_keyclass cstr
#define i_rawclass crawstr
- #define i_keyfrom cstr_from
#ifndef i_tag
#define i_tag str
#endif
@@ -159,20 +155,28 @@
#endif
#ifdef i_rawclass
- #if !defined i_cmp && !defined i_no_cmp
+ #if !(defined i_cmp || defined i_no_cmp)
#define i_cmp c_PASTE(i_keyraw, _cmp)
#endif
- #if !defined i_hash && !defined i_no_hash
+ #if !(defined i_hash || defined i_no_hash || defined i_no_cmp)
#define i_hash c_PASTE(i_keyraw, _hash)
#endif
#endif
+#if !defined i_keyraw && !defined i_no_clone
+ #if !defined i_keyfrom && defined i_keyclone
+ #define i_keyfrom i_keyclone
+ #elif !defined i_keyclone && defined i_keyfrom
+ #define i_keyclone i_keyfrom
+ #endif
+#endif
+
#if !defined i_key
#error "No i_key or i_val defined"
#elif defined i_keyraw ^ defined i_keyto
- #error "Both i_keyraw/valraw and i_keyto/valto must be defined, if any"
-#elif defined i_keyfrom && !defined i_keyraw
- #error "i_keyfrom/valfrom defined without i_keyraw/valraw"
+ #error "Both i_keyraw/i_valraw and i_keyto/i_valto must be defined, if any"
+#elif !defined i_no_clone && (defined i_keyclone ^ defined i_keydrop)
+ #error "Both i_keyclone/i_valclone and i_keydrop/i_valdrop must be defined, if any"
#elif defined i_from || defined i_drop
#error "i_from / i_drop not supported. Define i_keyfrom/i_valfrom and/or i_keydrop/i_valdrop instead"
#endif
@@ -180,18 +184,13 @@
#ifndef i_tag
#define i_tag i_key
#endif
-#if c_option(c_no_clone)
- #define i_no_clone
-#elif !(defined i_keyclone || defined i_no_clone) && (defined i_keydrop || defined i_keyraw)
- #error i_keyclone/valclone should be defined when i_keydrop/valdrop or i_keyraw/valraw is defined
-#endif
#ifndef i_keyraw
#define i_keyraw i_key
#endif
#ifndef i_keyfrom
#define i_keyfrom c_default_clone
#else
- #define _i_has_from
+ #define i_has_emplace
#endif
#ifndef i_keyto
#define i_keyto c_default_toraw
@@ -203,24 +202,33 @@
#define i_keydrop c_default_drop
#endif
-// i_eq, i_less, i_cmp
-#if !defined i_eq && (defined i_cmp || defined i_less)
- #define i_eq(x, y) !(i_cmp(x, y))
-#elif !defined i_eq
- #define i_eq c_default_eq
-#endif
-#if defined i_less && defined i_cmp
- #error "Only one of i_less and i_cmp may be defined"
-#elif !defined i_less && !defined i_cmp
- #define i_less c_default_less
-#elif !defined i_less
- #define i_less(x, y) (i_cmp(x, y)) < 0
-#endif
-#ifndef i_cmp
- #define i_cmp(x, y) (i_less(y, x)) - (i_less(x, y))
+#ifndef i_no_cmp
+ #if defined i_cmp || defined i_less || defined i_native_cmp
+ #define _i_has_cmp
+ #endif
+ #if defined i_eq || defined i_native_cmp
+ #define _i_has_eq
+ #endif
+
+ // i_eq, i_less, i_cmp
+ #if !defined i_eq && (defined i_cmp || defined i_less)
+ #define i_eq(x, y) !(i_cmp(x, y))
+ #elif !defined i_eq
+ #define i_eq(x, y) *x == *y
+ #endif
+ #if defined i_cmp && defined i_less
+ #error "Only one of i_cmp and i_less may be defined"
+ #elif defined i_cmp
+ #define i_less(x, y) (i_cmp(x, y)) < 0
+ #elif !defined i_less
+ #define i_less(x, y) *x < *y
+ #endif
+ #ifndef i_cmp
+ #define i_cmp(x, y) (i_less(y, x)) - (i_less(x, y))
+ #endif
#endif
-#ifndef i_hash
+#if !defined i_hash && (!(defined _i_cbox || defined _i_carc) || defined i_native_cmp)
#define i_hash c_default_hash
#endif
@@ -228,8 +236,7 @@
#ifdef i_val_str
#define i_valclass cstr
- #define i_valraw crawstr
- #define i_valfrom cstr_from
+ #define i_valraw const char*
#elif defined i_val_ssv
#define i_valclass cstr
#define i_valraw csview
@@ -256,20 +263,29 @@
#endif
#endif
+#if !defined i_valraw && !defined i_no_clone
+ #if !defined i_valfrom && defined i_valclone
+ #define i_valfrom i_valclone
+ #elif !defined i_valclone && defined i_valfrom
+ #define i_valclone i_valfrom
+ #endif
+#endif
+
#ifndef i_val
#error "i_val* must be defined for maps"
+#elif defined i_valraw ^ defined i_valto
+ #error "Both i_valraw and i_valto must be defined, if any"
+#elif !defined i_no_clone && (defined i_valclone ^ defined i_valdrop)
+ #error "Both i_valclone and i_valdrop must be defined, if any"
#endif
-#if !(defined i_valclone || defined i_no_clone) && (defined i_valdrop || defined i_valraw)
- #error i_valclone should be defined when i_valdrop or i_valraw is defined
-#endif
#ifndef i_valraw
#define i_valraw i_val
#endif
#ifndef i_valfrom
#define i_valfrom c_default_clone
#else
- #define _i_has_from
+ #define i_has_emplace
#endif
#ifndef i_valto
#define i_valto c_default_toraw
@@ -289,6 +305,7 @@
#ifndef i_valraw
#define i_valraw i_keyraw
#endif
-#ifndef _i_has_from
+#ifndef i_has_emplace
#define i_no_emplace
#endif
+#endif