summaryrefslogtreecommitdiffhomepage
path: root/include/stc/cbox.h
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-12-22 08:49:19 +0100
committerTyge Løvset <[email protected]>2021-12-22 08:50:15 +0100
commit6e65e30c6e3c2bc271d3885e749ceb0289bbd9cf (patch)
treeccffa7b7dde19fb551f99c7eed529bdc7308e494 /include/stc/cbox.h
parent1b90b6c3eea0f3e07f8a2d2abe3686917d1d86a8 (diff)
downloadSTC-modified-6e65e30c6e3c2bc271d3885e749ceb0289bbd9cf.tar.gz
STC-modified-6e65e30c6e3c2bc271d3885e749ceb0289bbd9cf.zip
Changed the c_apply() and c_apply_pair() to one new c_apply() API. Added c_pair(v) for convenience.
Diffstat (limited to 'include/stc/cbox.h')
-rw-r--r--include/stc/cbox.h33
1 files changed, 20 insertions, 13 deletions
diff --git a/include/stc/cbox.h b/include/stc/cbox.h
index bcd9bd8c..37687134 100644
--- a/include/stc/cbox.h
+++ b/include/stc/cbox.h
@@ -86,10 +86,15 @@ STC_INLINE _cx_self
_cx_memb(_from_ptr)(i_val* p) { return c_make(_cx_self){p}; }
STC_INLINE _cx_self
-_cx_memb(_new)(i_val val) {
+_cx_memb(_from)(i_val val) {
return c_make(_cx_self){c_new(i_val, val)};
}
+STC_INLINE i_val
+_cx_memb(_toraw)(const _cx_self* self) {
+ return *self->get;
+}
+
// destructor
STC_INLINE void
_cx_memb(_drop)(_cx_self* self) {
@@ -109,16 +114,18 @@ _cx_memb(_reset)(_cx_self* self) {
// take ownership of val
STC_INLINE void
-_cx_memb(_reset_new)(_cx_self* self, i_val val) {
+_cx_memb(_reset_from)(_cx_self* self, i_val val) {
if (self->get) { i_valdrop(self->get); *self->get = val; }
else self->get = c_new(i_val, val);
}
-#if !c_option(c_no_clone)
+#if !c_option(c_no_clone)
+ //#ifndef _i_valraw_default
STC_INLINE _cx_self
- _cx_memb(_from)(i_valraw raw) {
+ _cx_memb(_new)(i_valraw raw) {
return c_make(_cx_self){c_new(i_val, i_valfrom(raw))};
}
+ //#endif
STC_INLINE _cx_self
_cx_memb(_clone)(_cx_self other) {
@@ -141,29 +148,29 @@ _cx_memb(_take)(_cx_self* self, _cx_self other) {
}
STC_INLINE uint64_t
-_cx_memb(_hash)(const _cx_self* self, size_t n) {
+_cx_memb(_value_hash)(const _cx_value* x, size_t n) {
#if c_option(c_no_cmp) && UINTPTR_MAX == UINT64_MAX
- return c_hash64(&self->get, 8);
+ return c_hash64(&x, 8);
#elif c_option(c_no_cmp)
- return c_hash32(&self->get, 4);
+ return c_hash32(&x, 4);
#else
- i_valraw rx = i_valto(self->get);
+ i_valraw rx = i_valto(x);
return i_hash(&rx, sizeof rx);
#endif
}
STC_INLINE int
-_cx_memb(_cmp)(const _cx_self* x, const _cx_self* y) {
+_cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) {
#if c_option(c_no_cmp)
- return c_default_cmp(&x->get, &y->get);
+ return c_default_cmp(&x, &y);
#else
- i_valraw rx = i_valto(x->get), ry = i_valto(x->get);
+ i_valraw rx = i_valto(x), ry = i_valto(x);
return i_cmp(&rx, &ry);
#endif
}
STC_INLINE bool
-_cx_memb(_eq)(const _cx_self* x, const _cx_self* y) {
- return !_cx_memb(_cmp)(x, y);
+_cx_memb(_value_eq)(const _cx_value* x, const _cx_value* y) {
+ return !_cx_memb(_value_cmp)(x, y);
}
#include "template.h"