diff options
| author | Tyge Løvset <[email protected]> | 2021-10-23 12:29:43 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-10-23 12:29:43 +0200 |
| commit | 0f95c005891b0d4b3b2610fdba241cf78c372d81 (patch) | |
| tree | ebf3cebe3ef6dc66f820ab063b1cc3a3b7861a38 /examples/sidebyside.cpp | |
| parent | 63a09f6492b022eccd1583fd9b69c450ae3a8935 (diff) | |
| download | STC-modified-0f95c005891b0d4b3b2610fdba241cf78c372d81.tar.gz STC-modified-0f95c005891b0d4b3b2610fdba241cf78c372d81.zip | |
Fixed bug in c_realloc() call ion cstack. Added assert in cmap_X_at(). Added a c++ example.
Diffstat (limited to 'examples/sidebyside.cpp')
| -rw-r--r-- | examples/sidebyside.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/examples/sidebyside.cpp b/examples/sidebyside.cpp new file mode 100644 index 00000000..0f645991 --- /dev/null +++ b/examples/sidebyside.cpp @@ -0,0 +1,46 @@ +#include <iostream>
+#include <map>
+#include <string>
+
+#define i_key_str
+#define i_val int
+#include <stc/cmap.h>
+
+#define i_key int
+#define i_val int
+#include <stc/cmap.h>
+
+int main() {
+ {
+ std::map<std::string, int> food = {{"burger", 5}, {"pizza", 12}, {"steak", 15}};
+ for (auto i: food)
+ std::cout << i.first << ", " << i.second << std::endl;
+ std::cout << std::endl;
+ }
+ c_auto (cmap_str, food)
+ {
+ c_apply_pair(cmap_str, emplace, &food, {{"burger", 5}, {"pizza", 12}, {"steak", 15}});
+ c_foreach (i, cmap_str, food)
+ printf("%s, %d\n", i.ref->first.str, 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;
+ for (auto i: hist)
+ std::cout << i.first << ", " << i.second << std::endl;
+ std::cout << std::endl;
+ }
+ c_auto (cmap_int, hist)
+ {
+ ++ cmap_int_emplace(&hist, 12, 100).ref->second;
+ ++ cmap_int_emplace(&hist, 13, 100).ref->second;
+ ++ cmap_int_emplace(&hist, 12, 100).ref->second;
+ c_foreach (i, cmap_int, hist)
+ printf("%d, %d\n", i.ref->first, i.ref->second);
+ puts("");
+ }
+}
\ No newline at end of file |
