diff options
| author | Tyge Løvset <[email protected]> | 2021-05-19 11:50:55 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-05-19 11:50:55 +0200 |
| commit | 1fc82cb434ee59615070ddab7382c0afc0100174 (patch) | |
| tree | af6fd7006c864f1ab33b23064d1d88841a3abedd /docs/csmap_api.md | |
| parent | a9ad1ad0d4f4d6b8f702b2a14bc9a508829da9ff (diff) | |
| parent | 9dfb59aefda90672521d543a56986bdbda3bba01 (diff) | |
| download | STC-modified-1fc82cb434ee59615070ddab7382c0afc0100174.tar.gz STC-modified-1fc82cb434ee59615070ddab7382c0afc0100174.zip | |
Merge branch 'master' of https://github.com/tylo-work/C99Containers into master
Diffstat (limited to 'docs/csmap_api.md')
| -rw-r--r-- | docs/csmap_api.md | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/docs/csmap_api.md b/docs/csmap_api.md index a5d0aeee..73f19c18 100644 --- a/docs/csmap_api.md +++ b/docs/csmap_api.md @@ -150,17 +150,18 @@ int main() {100, "Red"}, {110, "Blue"}, }); - /* put replaces existing mapped value: */ - csmap_id_emplace_or_assign(&idnames, 110, "White"); - /* put a constructed mapped value into map: */ - csmap_id_insert_or_assign(&idnames, 120, cstr_from_fmt("#%08x", col)); - /* emplace adds only when key does not exist: */ - csmap_id_emplace(&idnames, 100, "Green"); - - c_foreach (i, csmap_id, idnames) - printf("%d: %s\n", i.ref->first, i.ref->second.str); - - csmap_id_del(&idnames); + c_defer (csmap_id_del(&idnames)) + { + /* put replaces existing mapped value: */ + csmap_id_emplace_or_assign(&idnames, 110, "White"); + /* put a constructed mapped value into map: */ + csmap_id_insert_or_assign(&idnames, 120, cstr_from_fmt("#%08x", col)); + /* emplace adds only when key does not exist: */ + csmap_id_emplace(&idnames, 100, "Green"); + + c_foreach (i, csmap_id, idnames) + printf("%d: %s\n", i.ref->first, i.ref->second.str); + } } ``` Output: @@ -189,17 +190,16 @@ using_csmap(vi, Vec3i, int, Vec3i_compare); int main() { - csmap_vi vecs = csmap_vi_init(); - - csmap_vi_emplace(&vecs, (Vec3i){100, 0, 0}, 1); - csmap_vi_emplace(&vecs, (Vec3i){ 0, 100, 0}, 2); - csmap_vi_emplace(&vecs, (Vec3i){ 0, 0, 100}, 3); - csmap_vi_emplace(&vecs, (Vec3i){100, 100, 100}, 4); - - c_foreach (i, csmap_vi, vecs) - printf("{ %3d, %3d, %3d }: %d\n", i.ref->first.x, i.ref->first.y, i.ref->first.z, i.ref->second); + c_withvar (csmap_vi, vecs) // define, init and defer destruction of vecs + { + csmap_vi_emplace(&vecs, (Vec3i){100, 0, 0}, 1); + csmap_vi_emplace(&vecs, (Vec3i){ 0, 100, 0}, 2); + csmap_vi_emplace(&vecs, (Vec3i){ 0, 0, 100}, 3); + csmap_vi_emplace(&vecs, (Vec3i){100, 100, 100}, 4); - csmap_vi_del(&vecs); + c_foreach (i, csmap_vi, vecs) + printf("{ %3d, %3d, %3d }: %d\n", i.ref->first.x, i.ref->first.y, i.ref->first.z, i.ref->second); + } } ``` Output: |
