summaryrefslogtreecommitdiffhomepage
path: root/examples/sidebyside.cpp
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-06-17 18:04:37 +0200
committerTyge Løvset <[email protected]>2022-06-17 18:04:37 +0200
commit755bcee8a97b2912d047895d37f5b60672486144 (patch)
tree86f662acd342394601984ff8e13f61a803c5275b /examples/sidebyside.cpp
parentfb39cd5db944d13b6de110885081e483234b453f (diff)
downloadSTC-modified-755bcee8a97b2912d047895d37f5b60672486144.tar.gz
STC-modified-755bcee8a97b2912d047895d37f5b60672486144.zip
Various refactoring. Renamed c_apply_arr() => c_apply_array()
Diffstat (limited to 'examples/sidebyside.cpp')
-rw-r--r--examples/sidebyside.cpp53
1 files changed, 28 insertions, 25 deletions
diff --git a/examples/sidebyside.cpp b/examples/sidebyside.cpp
index 4d63496b..f2021436 100644
--- a/examples/sidebyside.cpp
+++ b/examples/sidebyside.cpp
@@ -1,54 +1,57 @@
#include <iostream>
#include <map>
#include <string>
-
-#define i_key_str
-#define i_val int
-#define i_tag si
-#include <stc/cmap.h>
+#include <stc/cstr.h>
#define i_key int
#define i_val int
#define i_tag ii
#include <stc/csmap.h>
+#define i_key_str
+#define i_val int
+#define i_tag si
+#include <stc/cmap.h>
+
int main() {
{
- std::map<std::string, int> food =
- {{"burger", 5}, {"pizza", 12}, {"steak", 15}};
+ std::map<int, int> hist;
+ hist.emplace(12, 100).first->second += 1;
+ hist.emplace(13, 100).first->second += 1;
+ hist.emplace(12, 100).first->second += 1;
- for (auto i: food)
+ for (auto i: hist)
std::cout << i.first << ", " << i.second << std::endl;
std::cout << std::endl;
}
- c_auto (cmap_si, food)
+
+ c_auto (csmap_ii, hist)
{
- c_apply(v, cmap_si_emplace(&food, c_pair(v)), cmap_si_raw,
- {{"burger", 5}, {"pizza", 12}, {"steak", 15}});
+ csmap_ii_insert(&hist, 12, 100).ref->second += 1;
+ csmap_ii_insert(&hist, 13, 100).ref->second += 1;
+ csmap_ii_insert(&hist, 12, 100).ref->second += 1;
- c_foreach (i, cmap_si, food)
- printf("%s, %d\n", i.ref->first.str, i.ref->second);
+ c_foreach (i, csmap_ii, hist)
+ printf("%d, %d\n", i.ref->first, i.ref->second);
puts("");
}
-
+ // ===================================================
{
- std::map<int, int> hist;
- ++ hist.emplace(12, 100).first->second;
- ++ hist.emplace(13, 100).first->second;
- ++ hist.emplace(12, 100).first->second;
+ std::map<std::string, int> food =
+ {{"burger", 5}, {"pizza", 12}, {"steak", 15}};
- for (auto i: hist)
+ for (auto i: food)
std::cout << i.first << ", " << i.second << std::endl;
std::cout << std::endl;
}
- c_auto (csmap_ii, hist)
+
+ c_auto (cmap_si, food)
{
- ++ csmap_ii_insert(&hist, 12, 100).ref->second;
- ++ csmap_ii_insert(&hist, 13, 100).ref->second;
- ++ csmap_ii_insert(&hist, 12, 100).ref->second;
+ c_apply(v, cmap_si_emplace(&food, c_pair(v)), cmap_si_raw,
+ {{"burger", 5}, {"pizza", 12}, {"steak", 15}});
- c_foreach (i, csmap_ii, hist)
- printf("%d, %d\n", i.ref->first, i.ref->second);
+ c_foreach (i, cmap_si, food)
+ printf("%s, %d\n", cstr_str(&i.ref->first), i.ref->second);
puts("");
}
}