summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Lovset <[email protected]>2023-05-19 19:06:37 +0200
committerTyge Lovset <[email protected]>2023-05-19 19:06:37 +0200
commitd629139d053fdc1ff24bc0dc1985e1a2d1a0ac47 (patch)
tree86af3209ee9f11d38cbb053ee658b0f2dae6565d /include
parent424e522d6f081bb8649777a3376e1dd5913daac8 (diff)
downloadSTC-modified-d629139d053fdc1ff24bc0dc1985e1a2d1a0ac47.tar.gz
STC-modified-d629139d053fdc1ff24bc0dc1985e1a2d1a0ac47.zip
Added container equality function to docs _eq(c1, c2).
Diffstat (limited to 'include')
-rw-r--r--include/stc/cdeq.h13
-rw-r--r--include/stc/cqueue.h18
-rw-r--r--include/stc/cstack.h11
3 files changed, 29 insertions, 13 deletions
diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h
index 0dbe7f5d..77fb015f 100644
--- a/include/stc/cdeq.h
+++ b/include/stc/cdeq.h
@@ -96,7 +96,6 @@ _cx_memb(_emplace_at)(_cx_self* self, _cx_iter it, const _cx_raw raw)
#if defined _i_has_eq || defined _i_has_cmp
STC_API _cx_iter _cx_memb(_find_in)(_cx_iter p1, _cx_iter p2, _cx_raw raw);
-STC_API bool _cx_memb(_eq)(const _cx_self* self, const _cx_self* other);
STC_INLINE _cx_iter
_cx_memb(_find)(const _cx_self* self, _cx_raw raw) {
@@ -183,18 +182,6 @@ _cx_memb(_find_in)(_cx_iter i1, _cx_iter i2, _cx_raw raw) {
}
return i1;
}
-
-STC_DEF bool
-_cx_memb(_eq)(const _cx_self* self, const _cx_self* other) {
- if (_cx_memb(_size)(self) != _cx_memb(_size)(other)) return false;
- for (_cx_iter i = _cx_memb(_begin)(self), j = _cx_memb(_begin)(other);
- i.ref; _cx_memb(_next)(&i), _cx_memb(_next)(&j))
- {
- const _cx_raw _rx = i_keyto(i.ref), _ry = i_keyto(j.ref);
- if (!(i_eq((&_rx), (&_ry)))) return false;
- }
- return true;
-}
#endif
#endif // IMPLEMENTATION
#define CDEQ_H_INCLUDED
diff --git a/include/stc/cqueue.h b/include/stc/cqueue.h
index 840c4fa6..1f2c7d0f 100644
--- a/include/stc/cqueue.h
+++ b/include/stc/cqueue.h
@@ -62,6 +62,10 @@ STC_INLINE _cx_value* _cx_memb(_emplace)(_cx_self* self, _cx_raw raw)
{ return _cx_memb(_push)(self, i_keyfrom(raw)); }
#endif
+#if defined _i_has_eq || defined _i_has_cmp
+STC_API bool _cx_memb(_eq)(const _cx_self* self, const _cx_self* other);
+#endif
+
#if !defined i_no_clone
STC_API _cx_self _cx_memb(_clone)(_cx_self cx);
STC_INLINE i_key _cx_memb(_value_clone)(i_key val)
@@ -211,6 +215,20 @@ _cx_memb(_clone)(_cx_self cx) {
return out;
}
#endif // i_no_clone
+
+#if defined _i_has_eq || defined _i_has_cmp
+STC_DEF bool
+_cx_memb(_eq)(const _cx_self* self, const _cx_self* other) {
+ if (_cx_memb(_size)(self) != _cx_memb(_size)(other)) return false;
+ for (_cx_iter i = _cx_memb(_begin)(self), j = _cx_memb(_begin)(other);
+ i.ref; _cx_memb(_next)(&i), _cx_memb(_next)(&j))
+ {
+ const _cx_raw _rx = i_keyto(i.ref), _ry = i_keyto(j.ref);
+ if (!(i_eq((&_rx), (&_ry)))) return false;
+ }
+ return true;
+}
+#endif
#endif // IMPLEMENTATION
#include "priv/template2.h"
#define CQUEUE_H_INCLUDED
diff --git a/include/stc/cstack.h b/include/stc/cstack.h
index 84bdb41b..bee7d17b 100644
--- a/include/stc/cstack.h
+++ b/include/stc/cstack.h
@@ -194,4 +194,15 @@ STC_INLINE intptr_t _cx_memb(_index)(const _cx_self* self, _cx_iter it)
STC_INLINE void _cx_memb(_adjust_end_)(_cx_self* self, intptr_t n)
{ self->_len += n; }
+#if defined _i_has_eq || defined _i_has_cmp
+STC_INLINE bool
+_cx_memb(_eq)(const _cx_self* self, const _cx_self* other) {
+ if (self->_len != other->_len) return false;
+ for (intptr_t i = 0; i < self->_len; ++i) {
+ const _cx_raw _rx = i_keyto(self->data+i), _ry = i_keyto(other->data+i);
+ if (!(i_eq((&_rx), (&_ry)))) return false;
+ }
+ return true;
+}
+#endif
#include "priv/template2.h"