diff options
| author | Tyge Lovset <[email protected]> | 2022-08-12 11:38:10 +0200 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2022-08-12 11:38:10 +0200 |
| commit | a417e5affc99233abb6dbb685154bfdea1b726e3 (patch) | |
| tree | 211f1e1c000d57ea7e5ca318c625996ce094dc76 /examples | |
| parent | f534db7ac4a993a05074868b8840a3a674ac76b4 (diff) | |
| download | STC-modified-a417e5affc99233abb6dbb685154bfdea1b726e3.tar.gz STC-modified-a417e5affc99233abb6dbb685154bfdea1b726e3.zip | |
More misc changes carc/cbox, cdeq/cvec.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/city.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/examples/city.c b/examples/city.c index 0fcee341..c6a9417f 100644 --- a/examples/city.c +++ b/examples/city.c @@ -32,8 +32,9 @@ static inline void City_drop(City* c) { #define i_type CityArc #define i_key_bind City -#include <stc/cbox.h> -//#include <stc/carc.h> // try instead of cbox.h +#define i_opt c_no_atomic +//#include <stc/cbox.h> +#include <stc/carc.h> // try instead of cbox.h #define i_type Cities #define i_key_arcbox CityArc @@ -50,17 +51,13 @@ int main(void) c_auto (Cities, cities, copy) c_auto (CityMap, map) { - struct City_s { const char *name, *country; float lat, lon; int pop; }; - - c_forarray (struct City_s, c, { - {"New York", "US", 4.3, 23.2, 9000000}, - {"Paris", "France", 4.3, 23.2, 9000000}, - {"Berlin", "Germany", 4.3, 23.2, 9000000}, - {"London", "UK", 4.3, 23.2, 9000000}, + c_forarray (City, c, { + {cstr_new("New York"), cstr_new("US"), 4.3, 23.2, 9000000}, + {cstr_new("Paris"), cstr_new("France"), 4.3, 23.2, 9000000}, + {cstr_new("Berlin"), cstr_new("Germany"), 4.3, 23.2, 9000000}, + {cstr_new("London"), cstr_new("UK"), 4.3, 23.2, 9000000}, }) { - Cities_emplace(&cities, (City){cstr_from(c->name), - cstr_from(c->country), - c->lat, c->lon, c->pop}); + Cities_emplace(&cities, *c); } copy = Cities_clone(cities); // share each element! @@ -76,12 +73,12 @@ int main(void) c_foreach (c, Cities, cities) printf("city:%s, %d, use:%ld\n", cstr_str(&c.ref->get->name), c.ref->get->population, - CityArc_use_count(*c.ref)); + CityArc_use_count(c.ref)); printf("\nMap:\n"); c_forpair (id, city, CityMap, map) printf("id:%d, city:%s, %d, use:%ld\n", *_.id, cstr_str(&_.city->get->name), - _.city->get->population, CityArc_use_count(*_.city)); + _.city->get->population, CityArc_use_count(_.city)); puts(""); } } |
