diff options
| author | Tyge Løvset <[email protected]> | 2022-09-02 23:45:11 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-09-02 23:45:11 +0200 |
| commit | 491a8cba3ee55a1200fc2de8ef3807dd8436f829 (patch) | |
| tree | f877ef241836ca369561cf62d2db465ef3cbeca0 /include | |
| parent | a2a18a52df4fc10ad453eba7cdfbe2d02a026f0b (diff) | |
| download | STC-modified-491a8cba3ee55a1200fc2de8ef3807dd8436f829.tar.gz STC-modified-491a8cba3ee55a1200fc2de8ef3807dd8436f829.zip | |
Change: carc and cbox defaults to pointer comparison when none of i_cmp, i_less or i_eq is specified. This removes annoying requirement.
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/carc.h | 14 | ||||
| -rw-r--r-- | include/stc/cbox.h | 10 | ||||
| -rw-r--r-- | include/stc/cdeq.h | 6 | ||||
| -rw-r--r-- | include/stc/clist.h | 6 | ||||
| -rw-r--r-- | include/stc/cvec.h | 6 | ||||
| -rw-r--r-- | include/stc/template.h | 4 |
6 files changed, 27 insertions, 19 deletions
diff --git a/include/stc/carc.h b/include/stc/carc.h index 6e8f7d38..d0adcceb 100644 --- a/include/stc/carc.h +++ b/include/stc/carc.h @@ -37,7 +37,6 @@ void Person_drop(Person* p) { #define i_type ArcPers #define i_key Person #define i_keydrop Person_drop -#define i_opt c_no_cmp #include <stc/carc.h> int main() { @@ -78,6 +77,9 @@ int main() { #ifndef _i_prefix #define _i_prefix carc_ #endif +#if !(defined i_cmp || defined i_less || defined i_eq || defined i_hash) + #define _i_no_cmp +#endif #include "template.h" typedef i_keyraw _cx_raw; @@ -146,10 +148,10 @@ STC_INLINE void _cx_memb(_reset_to)(_cx_self* self, _cx_value* p) { *self = _cx_memb(_from_ptr)(p); } -#if !defined _i_no_clone && !defined _i_no_emplace +#if !defined _i_no_emplace STC_INLINE _cx_self _cx_memb(_new)(_cx_raw raw) { return _cx_memb(_from)(i_keyfrom(raw)); } -#endif // !_i_no_clone +#endif // !_i_no_emplace // does not use i_keyclone, so OK to always define. STC_INLINE _cx_self _cx_memb(_clone)(_cx_self ptr) { @@ -172,7 +174,7 @@ STC_INLINE void _cx_memb(_take)(_cx_self* self, _cx_self ptr) { } STC_INLINE uint64_t _cx_memb(_value_hash)(const _cx_value* x) { - #if c_option(c_no_cmp) + #if defined _i_no_cmp return c_default_hash(&x); #else _cx_raw rx = i_keyto(x); @@ -181,7 +183,7 @@ STC_INLINE uint64_t _cx_memb(_value_hash)(const _cx_value* x) { } STC_INLINE int _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) { - #if c_option(c_no_cmp) + #if defined _i_no_cmp return c_default_cmp(&x, &y); #else _cx_raw rx = i_keyto(x), ry = i_keyto(y); @@ -190,7 +192,7 @@ STC_INLINE int _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) { } STC_INLINE bool _cx_memb(_value_eq)(const _cx_value* x, const _cx_value* y) { - #if c_option(c_no_cmp) + #if defined _i_no_cmp return x == y; #else _cx_raw rx = i_keyto(x), ry = i_keyto(y); diff --git a/include/stc/cbox.h b/include/stc/cbox.h index 02a73fdc..fc300de3 100644 --- a/include/stc/cbox.h +++ b/include/stc/cbox.h @@ -41,7 +41,6 @@ void Person_drop(Person* p) { } #define i_key_bind Person // bind Person clone+drop fn's -#define i_opt c_no_cmp // compare by .get addresses only #define i_type PBox #include <stc/cbox.h> @@ -71,6 +70,9 @@ int main() { #ifndef _i_prefix #define _i_prefix cbox_ #endif +#if !(defined i_cmp || defined i_less || defined i_eq || defined i_hash) + #define _i_no_cmp +#endif #include "template.h" typedef i_keyraw _cx_raw; @@ -147,7 +149,7 @@ STC_INLINE void _cx_memb(_take)(_cx_self* self, _cx_self other) { } STC_INLINE uint64_t _cx_memb(_value_hash)(const _cx_value* x) { - #if c_option(c_no_cmp) + #if defined _i_no_cmp return c_default_hash(&x); #else _cx_raw rx = i_keyto(x); @@ -156,7 +158,7 @@ STC_INLINE uint64_t _cx_memb(_value_hash)(const _cx_value* x) { } STC_INLINE int _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) { - #if c_option(c_no_cmp) + #if defined _i_no_cmp return c_default_cmp(&x, &y); #else _cx_raw rx = i_keyto(x), ry = i_keyto(y); @@ -165,7 +167,7 @@ STC_INLINE int _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) { } STC_INLINE bool _cx_memb(_value_eq)(const _cx_value* x, const _cx_value* y) { - #if c_option(c_no_cmp) + #if defined _i_no_cmp return x == y; #else _cx_raw rx = i_keyto(x), ry = i_keyto(y); diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index a8c880f2..b4f02081 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -57,7 +57,7 @@ STC_API _cx_iter _cx_memb(_emplace_range)(_cx_self* self, _cx_value* pos, const _cx_raw* p1, const _cx_raw* p2); #endif // _i_no_emplace -#if !c_option(c_no_cmp) +#if !defined _i_no_cmp STC_API _cx_iter _cx_memb(_find_in)(_cx_iter p1, _cx_iter p2, _cx_raw raw); STC_API int _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y); #endif @@ -177,7 +177,7 @@ _cx_memb(_emplace_at)(_cx_self* self, _cx_iter it, _cx_raw raw) { } #endif // !_i_no_emplace -#if !c_option(c_no_cmp) +#if !defined _i_no_cmp STC_INLINE _cx_iter _cx_memb(_find)(const _cx_self* self, _cx_raw raw) { @@ -427,7 +427,7 @@ _cx_memb(_emplace_range)(_cx_self* self, _cx_value* pos, } #endif // !_i_no_emplace -#if !c_option(c_no_cmp) +#if !defined _i_no_cmp STC_DEF _cx_iter _cx_memb(_find_in)(_cx_iter i1, _cx_iter i2, _cx_raw raw) { diff --git a/include/stc/clist.h b/include/stc/clist.h index 5b9cf0d3..7e47f7b7 100644 --- a/include/stc/clist.h +++ b/include/stc/clist.h @@ -101,7 +101,7 @@ STC_API _cx_value* _cx_memb(_push_node_front)(_cx_self* self, _cx_node* nod STC_API _cx_iter _cx_memb(_insert_at)(_cx_self* self, _cx_iter it, i_key value); STC_API _cx_iter _cx_memb(_erase_at)(_cx_self* self, _cx_iter it); STC_API _cx_iter _cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2); -#if !c_option(c_no_cmp) +#if !defined _i_no_cmp STC_API size_t _cx_memb(_remove)(_cx_self* self, _cx_raw val); STC_API _cx_iter _cx_memb(_find_in)(_cx_iter it1, _cx_iter it2, _cx_raw val); STC_API int _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y); @@ -181,7 +181,7 @@ _cx_memb(_splice_range)(_cx_self* self, _cx_iter it, return _cx_memb(_splice)(self, it, &tmp); } -#if !c_option(c_no_cmp) +#if !defined _i_no_cmp STC_INLINE _cx_iter _cx_memb(_find)(const _cx_self* self, _cx_raw val) { return _cx_memb(_find_in)(_cx_memb(_begin)(self), _cx_memb(_end)(self), val); @@ -378,7 +378,7 @@ _cx_memb(_split_off)(_cx_self* self, _cx_iter it1, _cx_iter it2) { return cx; } -#if !c_option(c_no_cmp) +#if !defined _i_no_cmp STC_DEF _cx_iter _cx_memb(_find_in)(_cx_iter it1, _cx_iter it2, _cx_raw val) { diff --git a/include/stc/cvec.h b/include/stc/cvec.h index fcf05c10..ff26de1e 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -89,7 +89,7 @@ STC_API _cx_iter _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, STC_API _cx_iter _cx_memb(_insert_range)(_cx_self* self, _cx_value* pos, const _cx_value* p1, const _cx_value* p2); STC_API _cx_iter _cx_memb(_insert_uninit)(_cx_self* self, _cx_value* pos, const size_t n); -#if !c_option(c_no_cmp) +#if !defined _i_no_cmp STC_API int _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y); STC_API _cx_iter _cx_memb(_find_in)(_cx_iter it1, _cx_iter it2, _cx_raw raw); STC_API _cx_iter _cx_memb(_binary_search_in)(_cx_iter it1, _cx_iter it2, _cx_raw raw, _cx_iter* lower_bound); @@ -213,7 +213,7 @@ STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, size_t n) STC_INLINE size_t _cx_memb(_index)(const _cx_self* cx, _cx_iter it) { return it.ref - cx->data; } -#if !c_option(c_no_cmp) +#if !defined _i_no_cmp STC_INLINE _cx_iter _cx_memb(_find)(const _cx_self* self, _cx_raw raw) { @@ -402,7 +402,7 @@ _cx_memb(_emplace_range)(_cx_self* self, _cx_value* pos, } #endif // !_i_no_emplace -#if !c_option(c_no_cmp) +#if !defined _i_no_cmp STC_DEF _cx_iter _cx_memb(_find_in)(_cx_iter i1, _cx_iter i2, _cx_raw raw) { const _cx_value* p2 = _it2_ptr(i1, i2); diff --git a/include/stc/template.h b/include/stc/template.h index 4597e02c..41ecf7b0 100644 --- a/include/stc/template.h +++ b/include/stc/template.h @@ -147,6 +147,9 @@ #ifndef i_tag #define i_tag i_key #endif +#if c_option(c_no_cmp) + #define _i_no_cmp +#endif #if c_option(c_no_clone) || (!defined i_keyclone && (defined i_keydrop || defined i_keyraw)) #define _i_no_clone #endif @@ -304,6 +307,7 @@ #undef _i_prefix #undef _i_has_from #undef _i_key_from_val +#undef _i_no_cmp #undef _i_no_clone #undef _i_no_emplace #undef _i_no_hash |
