summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-08-01 20:50:29 +0200
committerTyge Løvset <[email protected]>2023-08-01 21:03:27 +0200
commitda14db1a3b3570d52f22c7ae4027d1a53b6ac862 (patch)
tree727514ca23bcfc8c5bab72d5c71405e2fec08451
parent7df124507b82bfb168a440392060bc0e03ce5c7e (diff)
downloadSTC-modified-da14db1a3b3570d52f22c7ae4027d1a53b6ac862.tar.gz
STC-modified-da14db1a3b3570d52f22c7ae4027d1a53b6ac862.zip
Added some checks that a proper i_cmp/(i_hash) is defined when i_keyraw conversion type is specified for maps. Advanced usage.
-rw-r--r--include/stc/cmap.h2
-rw-r--r--include/stc/cpque.h2
-rw-r--r--include/stc/priv/template.h20
3 files changed, 17 insertions, 7 deletions
diff --git a/include/stc/cmap.h b/include/stc/cmap.h
index 2dd8cbe6..cd7430ba 100644
--- a/include/stc/cmap.h
+++ b/include/stc/cmap.h
@@ -69,6 +69,7 @@ struct chash_slot { uint8_t hashx; };
#define _i_SET_ONLY c_true
#define _i_keyref(vp) (vp)
#endif
+#define _i_ishash
#include "priv/template.h"
#ifndef i_is_forward
_cx_DEFTYPES(_c_chash_types, _cx_Self, i_key, i_val, _i_MAP_ONLY, _i_SET_ONLY);
@@ -463,6 +464,7 @@ _cx_MEMB(_erase_entry)(_cx_Self* self, _cx_value* _val) {
#undef i_max_load_factor
#undef _i_isset
#undef _i_ismap
+#undef _i_ishash
#undef _i_keyref
#undef _i_MAP_ONLY
#undef _i_SET_ONLY
diff --git a/include/stc/cpque.h b/include/stc/cpque.h
index ca51eeff..520514ef 100644
--- a/include/stc/cpque.h
+++ b/include/stc/cpque.h
@@ -29,6 +29,7 @@
#endif
#define _i_prefix cpque_
+#define _i_ispque
#include "priv/template.h"
#ifndef i_is_forward
_cx_DEFTYPES(_c_cpque_types, _cx_Self, i_key);
@@ -160,3 +161,4 @@ _cx_MEMB(_push)(_cx_Self* self, _cx_value value) {
#endif
#define CPQUE_H_INCLUDED
#include "priv/template2.h"
+#undef _i_ispque \ No newline at end of file
diff --git a/include/stc/priv/template.h b/include/stc/priv/template.h
index ccdce718..0f4ac893 100644
--- a/include/stc/priv/template.h
+++ b/include/stc/priv/template.h
@@ -171,6 +171,15 @@
#endif
#endif
+#ifndef i_no_cmp
+ #if defined i_cmp || defined i_less || defined i_cmp_native
+ #define _i_has_cmp
+ #endif
+ #if defined i_eq || defined i_cmp_native
+ #define _i_has_eq
+ #endif
+#endif
+
#if !defined i_key
#error "No i_key or i_val defined"
#elif defined i_keyraw ^ defined i_keyto
@@ -179,6 +188,10 @@
#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"
+#elif defined i_keyraw && defined _i_ishash && !(defined i_hash && (defined _i_has_cmp || defined i_eq))
+ #error "For cmap/cset, both i_hash and i_eq (or i_less or i_cmp) must be defined when i_keyraw is defined."
+#elif defined i_keyraw && (defined _i_ismap || defined _i_isset || defined _i_ispque) && !defined _i_has_cmp
+ #error "For csmap/csset/cpque, i_cmp or i_less must be defined when i_keyraw is defined."
#endif
#ifndef i_tag
@@ -203,13 +216,6 @@
#endif
#ifndef i_no_cmp
- #if defined i_cmp || defined i_less || defined i_cmp_native
- #define _i_has_cmp
- #endif
- #if defined i_eq || defined i_cmp_native
- #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))