From b0d60c33a073782fe0bb08c835ca9db0b94145d0 Mon Sep 17 00:00:00 2001 From: Tyge Lovset Date: Mon, 18 Apr 2022 12:12:01 +0200 Subject: Removed i_drop and i_from template specifiers to reduce redundancies and add clarity (error given if used): use i_valdrop/i_valfrom and i_keydrop/i_keyfrom instead. Added missing at_mut() function to cdeq. --- include/stc/cdeq.h | 10 +++++----- include/stc/template.h | 20 ++++---------------- 2 files changed, 9 insertions(+), 21 deletions(-) (limited to 'include') diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index baa7cb04..0dfe79dd 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -103,16 +103,16 @@ STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, intptr_t offs) #if !defined _i_queue +STC_INLINE size_t _cx_memb(_index)(_cx_self cx, _cx_iter it) + { return it.ref - cx.data; } STC_INLINE void _cx_memb(_pop_back)(_cx_self* self) { _cx_value* p = &self->data[--cdeq_rep_(self)->size]; i_valdrop(p); } STC_INLINE const _cx_value* _cx_memb(_at)(const _cx_self* self, const size_t idx) { - assert(idx < cdeq_rep_(self)->size); - return self->data + idx; + assert(idx < cdeq_rep_(self)->size); return self->data + idx; } - -STC_INLINE size_t _cx_memb(_index)(_cx_self cx, _cx_iter it) { - return it.ref - cx.data; +STC_INLINE _cx_value* _cx_memb(_at_mut)(_cx_self* self, const size_t idx) { + assert(idx < cdeq_rep_(self)->size); return self->data + idx; } STC_INLINE _cx_iter diff --git a/include/stc/template.h b/include/stc/template.h index 243eec6f..934a5d4a 100644 --- a/include/stc/template.h +++ b/include/stc/template.h @@ -97,21 +97,11 @@ #error "if i_keyraw defined, i_keyfrom (and often i_keyto) must be defined" #endif -/* Resolve i_drop and i_from here */ -#if defined i_drop && !defined i_keydrop && defined _i_isset - #define i_keydrop i_drop -#elif defined i_drop && !defined i_key - #define i_valdrop i_drop -#elif defined i_drop - #error "i_drop not supported when i_key defined. Define i_keydrop/i_valdrop instead." +#if defined i_drop + #error "i_drop not supported Define i_keydrop/i_valdrop instead." #endif - -#if defined i_from && !defined i_keyfrom && defined _i_isset - #define i_keyfrom i_from -#elif defined i_from && !defined i_key - #define i_valfrom i_from -#elif defined i_from - #error "i_from not supported when i_key defined. Define i_keyfrom/i_valfrom instead." +#if defined i_from + #error "i_from not supported. Define i_keyfrom/i_valfrom instead." #endif #ifdef i_val_str @@ -237,8 +227,6 @@ #undef i_cmp #undef i_eq #undef i_hash -#undef i_from -#undef i_drop #undef i_size #undef i_val -- cgit v1.2.3