diff options
| author | Tyge Lovset <[email protected]> | 2022-07-11 23:53:06 +0200 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2022-07-11 23:53:06 +0200 |
| commit | 839efba934c8623f2dea31e7f8bb2857624c6908 (patch) | |
| tree | 218e165ae2b65f6c2be41ea8169fb71432b4e68e /examples | |
| parent | 5082397444550d9486783fe498629524a64d564e (diff) | |
| download | STC-modified-839efba934c8623f2dea31e7f8bb2857624c6908.tar.gz STC-modified-839efba934c8623f2dea31e7f8bb2857624c6908.zip | |
Fixed documentation changes for size, capacity, empty. Minor changes in some ex. and map shootout.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/box.c | 14 | ||||
| -rw-r--r-- | examples/box2.c | 8 |
2 files changed, 11 insertions, 11 deletions
diff --git a/examples/box.c b/examples/box.c index 70b0ab08..ef2ff28b 100644 --- a/examples/box.c +++ b/examples/box.c @@ -48,19 +48,19 @@ int main() printf("orig: %s %s\n", cstr_str(&p.get->name), cstr_str(&p.get->last)); printf("copy: %s %s\n", cstr_str(&q.get->name), cstr_str(&q.get->last)); - Persons_push_back(&vec, PBox_make(Person_new("Dale", "Cooper"))); - Persons_push_back(&vec, PBox_make(Person_new("Audrey", "Home"))); - + Persons_push(&vec, PBox_make(Person_new("Dale", "Cooper"))); + Persons_push(&vec, PBox_make(Person_new("Audrey", "Home"))); + // NB! Clone p and q to the vector using emplace_back() - c_apply(v, Persons_push_back(&vec, PBox_clone(*v)), PBox, {p, q}); + c_apply(v, Persons_push(&vec, PBox_clone(*v)), PBox, {p, q}); c_foreach (i, Persons, vec) printf("%s %s\n", cstr_str(&i.ref->get->name), cstr_str(&i.ref->get->last)); puts(""); - - // Look-up Audrey! Use a (fake) temporary PBox for lookup. + + // Look-up Audrey! Create a temporary Person for lookup. c_autovar (Person a = Person_new("Audrey", "Home"), Person_drop(&a)) { - const PBox *v = Persons_get(&vec, a); + const PBox *v = Persons_get(&vec, a); // lookup if (v) printf("found: %s %s\n", cstr_str(&v->get->name), cstr_str(&v->get->last)); } puts(""); diff --git a/examples/box2.c b/examples/box2.c index c44802d3..0896388e 100644 --- a/examples/box2.c +++ b/examples/box2.c @@ -10,7 +10,7 @@ struct { double y; } typedef Point; -// A Rectangle can be specified by where its top left and bottom right +// A Rectangle can be specified by where its top left and bottom right // corners are in space struct { Point top_left; @@ -27,7 +27,7 @@ struct { // Box in box: #define i_val_arcbox cbox_Point // NB: use i_val_arcbox when value is a cbox or carc! - // it will auto-set i_valdrop, i_valfrom, i_cmp for you. + // it will auto define i_valdrop, i_valfrom, and i_cmp. #define i_opt c_no_cmp #define i_tag BoxPoint #include <stc/cbox.h> // cbox_BoxPoint @@ -43,7 +43,6 @@ cbox_Point boxed_origin(void) { int main(void) { - // (all the type annotations are superfluous) // Stack allocated variables Point point = origin(); Rectangle rectangle = (Rectangle){ @@ -51,11 +50,12 @@ int main(void) { .bottom_right = (Point){ .x=3.0, .y=-4.0 } }; - // Heap allocated rectangle + // Declare auto-deleted box objects c_auto (cbox_Rectangle, boxed_rectangle) c_auto (cbox_Point, boxed_point) c_auto (cbox_BoxPoint, box_in_a_box) { + // Heap allocated rectangle boxed_rectangle = cbox_Rectangle_make((Rectangle){ .top_left = origin(), .bottom_right = (Point){ .x=3.0, .y=-4.0 } |
