add C++ implementation of CX_HASH_KEY()

Mon, 29 Sep 2025 23:25:31 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 29 Sep 2025 23:25:31 +0200
changeset 1403
09eca27b27e9
parent 1402
6fa42f7e2624
child 1404
ae80e36c05c7

add C++ implementation of CX_HASH_KEY()

relates to #731

src/cx/hash_key.h file | annotate | diff | comparison | revisions
--- a/src/cx/hash_key.h	Sun Sep 28 22:32:42 2025 +0200
+++ b/src/cx/hash_key.h	Mon Sep 29 23:25:31 2025 +0200
@@ -223,6 +223,7 @@
     return key;
 }
 
+#ifndef __cplusplus
 /**
  * Creates a hash key from any of the supported types with implicit length.
  *
@@ -245,7 +246,7 @@
         uint32_t: cx_hash_key_u32, \
         uint64_t: cx_hash_key_u64) \
         (key)
-
+#endif // __cplusplus
 
 /**
  * Computes a hash key from a UCX string.
@@ -270,6 +271,38 @@
 
 #ifdef __cplusplus
 } // extern "C"
+
+// ----------------------------------------------------------
+// Overloads of CX_HASH_KEY (the C++ version of a _Generic)
+// ----------------------------------------------------------
+
+static inline CxHashKey CX_HASH_KEY(CxHashKey key) {
+    return key;
+}
+
+static inline CxHashKey CX_HASH_KEY(cxstring str) {
+    return cx_hash_key_cxstr(str);
+}
+
+static inline CxHashKey CX_HASH_KEY(cxmutstr str) {
+    return cx_hash_key_mutstr(str);
+}
+
+static inline CxHashKey CX_HASH_KEY(const char *str) {
+    return cx_hash_key_str(str);
+}
+
+static inline CxHashKey CX_HASH_KEY(const unsigned char *str) {
+    return cx_hash_key_ustr(str);
+}
+
+static inline CxHashKey CX_HASH_KEY(uint32_t key) {
+    return cx_hash_key_u32(key);
+}
+
+static inline CxHashKey CX_HASH_KEY(uint64_t key) {
+    return cx_hash_key_u64(key);
+}
 #endif
 
 #endif // UCX_HASH_KEY_H

mercurial