diff options
| author | Tyge Løvset <[email protected]> | 2022-08-06 17:48:06 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-08-06 17:48:06 +0200 |
| commit | 618b5704e6f85cfe1b6e5c9c9373abe76a8bb628 (patch) | |
| tree | 4e25a538c8ba3fd58bb25b90ff6dc54adfb31aa4 /docs/csmap_api.md | |
| parent | 927fa8093ea0bc1e25586e60c47cf1dd8a311d9e (diff) | |
| download | STC-modified-618b5704e6f85cfe1b6e5c9c9373abe76a8bb628.tar.gz STC-modified-618b5704e6f85cfe1b6e5c9c9373abe76a8bb628.zip | |
c_apply() deprecated: replaced with c_forarray() macro. Updated and improved README.md docs.
Diffstat (limited to 'docs/csmap_api.md')
| -rw-r--r-- | docs/csmap_api.md | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/docs/csmap_api.md b/docs/csmap_api.md index 01b77cb4..c3e3f3ea 100644 --- a/docs/csmap_api.md +++ b/docs/csmap_api.md @@ -113,11 +113,11 @@ int main() // Create a sorted map of three strings (maps to string) c_auto (csmap_str, colors) // RAII { - c_apply(v, csmap_str_emplace(&colors, c_pair(v)), csmap_str_raw, { + c_forarray (csmap_str_raw, v, { {"RED", "#FF0000"}, {"GREEN", "#00FF00"}, {"BLUE", "#0000FF"} - }); + }) csmap_str_emplace(&colors, v->first, v->second); // Iterate and print keys and values of sorted map c_foreach (i, csmap_str, colors) { @@ -159,14 +159,15 @@ int main() csmap_id idnames = csmap_id_init(); c_autodefer (csmap_id_drop(&idnames)) { - c_apply(v, csmap_id_emplace(&idnames, c_pair(v)), csmap_id_raw, { - {100, "Red"}, - {110, "Blue"}, - }); + c_forarray (csmap_id_raw, v, {{100, "Red"}, {110, "Blue"}}) + csmap_id_emplace(&idnames, v->first, v->second); + // 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"); |
