summaryrefslogtreecommitdiffhomepage
path: root/include/stc/cstack.h
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-08-17 09:35:40 +0200
committerGitHub <[email protected]>2022-08-17 09:35:40 +0200
commit0681b8a9af2ac6041e937bc8ca7bc8d496dcc0d4 (patch)
tree03825b177d4d5259f629957b751b000e1b224db1 /include/stc/cstack.h
parent17f1d2ed83952df00525f4be1d30a6c12e04a0f6 (diff)
parenta06463c2f0747bc142a9d5b2bf455c64aaf39890 (diff)
downloadSTC-modified-0681b8a9af2ac6041e937bc8ca7bc8d496dcc0d4.tar.gz
STC-modified-0681b8a9af2ac6041e937bc8ca7bc8d496dcc0d4.zip
Merge pull request #34 from tylov/iter_exp_dont_use
VERSION 4.0 RC
Diffstat (limited to 'include/stc/cstack.h')
-rw-r--r--include/stc/cstack.h15
1 files changed, 9 insertions, 6 deletions
diff --git a/include/stc/cstack.h b/include/stc/cstack.h
index 46d209ca..e1839d37 100644
--- a/include/stc/cstack.h
+++ b/include/stc/cstack.h
@@ -169,15 +169,18 @@ STC_INLINE i_keyraw _cx_memb(_value_toraw)(const _cx_value* val)
{ return i_keyto(val); }
#endif // !_i_no_clone
-STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self)
- { return c_make(_cx_iter){(_cx_value*)self->data}; }
+STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) {
+ return c_make(_cx_iter){self->size ? (_cx_value*)self->data : NULL,
+ (_cx_value*)self->data + self->size};
+}
STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self)
- { return c_make(_cx_iter){(_cx_value*)self->data + self->size}; }
+ { return c_make(_cx_iter){NULL, (_cx_value*)self->data + self->size}; }
-STC_INLINE void _cx_memb(_next)(_cx_iter* it) { ++it->ref; }
+STC_INLINE void _cx_memb(_next)(_cx_iter* it)
+ { if (++it->ref == it->end) it->ref = NULL; }
-STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, intptr_t offs)
- { it.ref += offs; return it; }
+STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, size_t n)
+ { if ((it.ref += n) >= it.end) it.ref = NULL ; return it; }
#include "template.h"