diff options
| author | Tyge Lovset <[email protected]> | 2022-08-11 22:21:17 +0200 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2022-08-11 22:21:17 +0200 |
| commit | 3c110651771642cf28d6998e101a197b0cb02a4b (patch) | |
| tree | 8d3952bb1e462311516b6cbc94eb1e88f35f7a10 /examples | |
| parent | 5cf6b762012168be51b32a1a85ab2bc33504f020 (diff) | |
| download | STC-modified-3c110651771642cf28d6998e101a197b0cb02a4b.tar.gz STC-modified-3c110651771642cf28d6998e101a197b0cb02a4b.zip | |
Added cmp, eq, hash to carc/cbox.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/music_arc.c | 19 |
1 files changed, 11 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:"); |
