diff options
| -rw-r--r-- | examples/music_arc.c | 19 | ||||
| -rw-r--r-- | include/stc/carc.h | 10 | ||||
| -rw-r--r-- | include/stc/cbox.h | 10 |
3 files changed, 31 insertions, 8 deletions
diff --git a/examples/music_arc.c b/examples/music_arc.c index 8cbcbb59..d933d125 100644 --- a/examples/music_arc.c +++ b/examples/music_arc.c @@ -8,6 +8,9 @@ struct Song cstr title; } typedef Song; +int Song_cmp(const Song* x, const Song* y) + { return cstr_cmp(&x->title, &y->title); } + Song Song_from(const char* artist, const char* title) { return (Song){cstr_from(artist), cstr_from(title)}; } @@ -19,7 +22,7 @@ void Song_drop(Song* s) { #define i_type SongArc #define i_val Song #define i_valdrop Song_drop -#define i_opt c_no_cmp +#define i_cmp Song_cmp #include <stc/carc.h> #define i_type SongVec @@ -30,18 +33,18 @@ void example3() { c_auto (SongVec, vec, vec2) { - c_forarray (SongArc, v, { - SongArc_make(Song_from("Bob Dylan", "The Times They Are A Changing")), - SongArc_make(Song_from("Aretha Franklin", "Bridge Over Troubled Water")), - SongArc_make(Song_from("Thalia", "Entre El Mar y Una Estrella")) - }) SongVec_push_back(&vec, *v); + c_forarray (Song, v, { + Song_from("Bob Dylan", "The Times They Are A Changing"), + Song_from("Aretha Franklin", "Bridge Over Troubled Water"), + Song_from("Thalia", "Entre El Mar y Una Estrella") + }) SongVec_emplace(&vec, *v); c_foreach (s, SongVec, vec) if (!cstr_equals(s.ref->get->artist, "Bob Dylan")) SongVec_push_back(&vec2, SongArc_clone(*s.ref)); - SongVec_push_back(&vec2, SongArc_make(Song_from("Michael Jackson", "Billie Jean"))); - SongVec_push_back(&vec2, SongArc_make(Song_from("Rihanna", "Stay"))); + SongVec_emplace(&vec2, Song_from("Michael Jackson", "Billie Jean")); + SongVec_emplace(&vec2, Song_from("Rihanna", "Stay")); c_forarray (SongVec, v, {vec, vec2}) { puts("VEC:"); diff --git a/include/stc/carc.h b/include/stc/carc.h index 62b33bed..20ba26b0 100644 --- a/include/stc/carc.h +++ b/include/stc/carc.h @@ -197,6 +197,16 @@ STC_INLINE bool _cx_memb(_value_eq)(const _cx_value* x, const _cx_value* y) { return i_eq((&rx), (&ry)); #endif } + +STC_INLINE uint64_t _cx_memb(_hash)(const _cx_self* x) + { return _cx_memb(_value_hash)(x->get); } + +STC_INLINE int _cx_memb(_cmp)(const _cx_self* x, const _cx_self* y) + { return _cx_memb(_value_cmp)(x->get, y->get); } + +STC_INLINE bool _cx_memb(_eq)(const _cx_self* x, const _cx_self* y) + { return _cx_memb(_value_eq)(x->get, y->get); } + #undef _i_atomic_inc #undef _i_atomic_dec_and_test #include "template.h" diff --git a/include/stc/cbox.h b/include/stc/cbox.h index 467dd645..d26a63c8 100644 --- a/include/stc/cbox.h +++ b/include/stc/cbox.h @@ -182,4 +182,14 @@ STC_INLINE bool _cx_memb(_value_eq)(const _cx_value* x, const _cx_value* y) { return i_eq((&rx), (&ry)); #endif } + +STC_INLINE uint64_t _cx_memb(_hash)(const _cx_self* x) + { return _cx_memb(_value_hash)(x->get); } + +STC_INLINE int _cx_memb(_cmp)(const _cx_self* x, const _cx_self* y) + { return _cx_memb(_value_cmp)(x->get, y->get); } + +STC_INLINE bool _cx_memb(_eq)(const _cx_self* x, const _cx_self* y) + { return _cx_memb(_value_eq)(x->get, y->get); } + #include "template.h" |
