summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-12-16 07:32:16 +0100
committerTyge Løvset <[email protected]>2021-12-16 07:32:16 +0100
commit183a89859ba9914ee0546e4482b40be199e52292 (patch)
treec199c6f1f5dead5e349f2b00f70bb33989ee520e /examples
parent7f264be520123c71211967a56d2826d272694edf (diff)
downloadSTC-modified-183a89859ba9914ee0546e4482b40be199e52292.tar.gz
STC-modified-183a89859ba9914ee0546e4482b40be199e52292.zip
Changed default comparison of csbox and csptr objects to comparing addresses to containing objects. If i_cmp is defined, it is used instead.
Diffstat (limited to 'examples')
-rw-r--r--examples/box2.c2
-rw-r--r--examples/sptr_erase.c8
-rw-r--r--examples/sptr_music.c1
-rw-r--r--examples/sptr_pthread.c1
-rw-r--r--examples/sptr_to_maps.c3
-rw-r--r--examples/words.c7
6 files changed, 8 insertions, 14 deletions
diff --git a/examples/box2.c b/examples/box2.c
index 86374a96..48266963 100644
--- a/examples/box2.c
+++ b/examples/box2.c
@@ -18,11 +18,9 @@ struct {
} typedef Rectangle;
#define i_val Point
-#define i_opt c_no_compare
#include <stc/cbox.h> // cbox_Point
#define i_val Rectangle
-#define i_opt c_no_compare
#include <stc/cbox.h> // cbox_Rectangle
// Box in box:
diff --git a/examples/sptr_erase.c b/examples/sptr_erase.c
index eada6fd6..4707abb1 100644
--- a/examples/sptr_erase.c
+++ b/examples/sptr_erase.c
@@ -4,10 +4,10 @@ void show_del(int* x) { printf("del: %d\n", *x); }
#define i_val int
#define i_del show_del // this "destroy" func shows which elements are destroyed
-// csptr/cbox will try to use default comparison of i_val (int) if no cmp func is specified,
-// unless 'i_opt c_no_compare' is defined, in which case pointer addresses are compared.
-// See the different results by commenting in the next line.
-//#define i_opt c_no_compare
+// csptr/cbox will use pointer address comparison of i_val if no i_cmp func is specified,
+// or 'i_opt c_no_compare' is defined, otherwise i_cmp is used to compare object values.
+// See the different results by commenting out the next line.
+#define i_cmp(x, y) (*(x) - *(y))
#include <stc/csptr.h> // csptr_int: shared pointer to int
#define i_val_ref csptr_int
diff --git a/examples/sptr_music.c b/examples/sptr_music.c
index e8e08b5f..fcb7a43f 100644
--- a/examples/sptr_music.c
+++ b/examples/sptr_music.c
@@ -20,7 +20,6 @@ void Song_del(Song* s) {
#define i_val Song
#define i_del Song_del
#define i_tag song
-#define i_opt c_no_compare
#include <stc/csptr.h> // define csptr_song
#define i_val_ref csptr_song
diff --git a/examples/sptr_pthread.c b/examples/sptr_pthread.c
index d82ea938..cfb845b6 100644
--- a/examples/sptr_pthread.c
+++ b/examples/sptr_pthread.c
@@ -15,7 +15,6 @@ void Base_del(Base* b) { printf("Base::~Base()\n"); }
#define i_val Base
#define i_del Base_del
-#define i_opt c_no_compare
#define i_tag base
#include <stc/csptr.h>
diff --git a/examples/sptr_to_maps.c b/examples/sptr_to_maps.c
index 77871304..a66e5b31 100644
--- a/examples/sptr_to_maps.c
+++ b/examples/sptr_to_maps.c
@@ -9,9 +9,8 @@
#define i_type Arc // (atomic) ref. counted type
#define i_val Map
#define i_del(p) (printf("del Arc:\n"), Map_del(p))
-// no comparison of Maps needed (or available), and
// no need for atomic ref. count in single thread:
-#define i_opt c_no_compare|c_no_atomic
+#define i_opt c_no_atomic
#include <stc/csptr.h>
#define i_type Stack
diff --git a/examples/words.c b/examples/words.c
index 951c3ded..6c0636dc 100644
--- a/examples/words.c
+++ b/examples/words.c
@@ -4,7 +4,6 @@
#define i_val_str
#include <stc/cvec.h>
-#define i_tag strn
#define i_key_str
#define i_val int
#include <stc/cmap.h>
@@ -12,7 +11,7 @@
int main1()
{
c_auto (cvec_str, words)
- c_auto (cmap_strn, word_map)
+ c_auto (cmap_str, word_map)
{
c_apply(cvec_str, emplace_back, &words, {
"this", "sentence", "is", "not", "a", "sentence",
@@ -20,10 +19,10 @@ int main1()
});
c_foreach (w, cvec_str, words) {
- cmap_strn_emplace(&word_map, w.ref->str, 0).ref->second += 1;
+ cmap_str_emplace(&word_map, w.ref->str, 0).ref->second += 1;
}
- c_foreach (i, cmap_strn, word_map) {
+ c_foreach (i, cmap_str, word_map) {
printf("%d occurrences of word '%s'\n",
i.ref->second, i.ref->first.str);
}