summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-09-23 20:55:07 +0200
committerTyge Løvset <[email protected]>2021-09-23 20:55:07 +0200
commit2686887e9091b3d56365b8ddc15db67324ee6727 (patch)
tree48e634d4eaebb7c67e3816f4110a150343f9c366
parent4ab5b3f6f5c841ab8c2202e838979a0d6df91530 (diff)
downloadSTC-modified-2686887e9091b3d56365b8ddc15db67324ee6727.tar.gz
STC-modified-2686887e9091b3d56365b8ddc15db67324ee6727.zip
Cleanup: Replaced c_emplace() macro with more general c_apply()/c_apply_pair() macros, and removed c_var() macro.
Removed CX_emplace_items() member functions in containers used by c_emplace().
-rw-r--r--README.md12
-rw-r--r--docs/ccommon_api.md10
-rw-r--r--docs/cdeq_api.md2
-rw-r--r--docs/clist_api.md11
-rw-r--r--docs/cmap_api.md6
-rw-r--r--docs/cpque_api.md3
-rw-r--r--docs/cqueue_api.md1
-rw-r--r--docs/cset_api.md46
-rw-r--r--docs/csmap_api.md7
-rw-r--r--docs/csset_api.md46
-rw-r--r--docs/cstack_api.md1
-rw-r--r--docs/cvec_api.md2
-rw-r--r--examples/advanced.c8
-rw-r--r--examples/cpque.c5
-rw-r--r--examples/csmap_erase.c4
-rw-r--r--examples/csmap_find.c2
-rw-r--r--examples/csmap_insert.c6
-rw-r--r--examples/csset_erase.c2
-rw-r--r--examples/inits.c8
-rw-r--r--examples/list.c2
-rw-r--r--examples/list_erase.c2
-rw-r--r--examples/list_splice.c4
-rw-r--r--examples/phonebook.c4
-rw-r--r--examples/priority.c2
-rw-r--r--examples/words.c2
-rw-r--r--include/stc/ccommon.h14
-rw-r--r--include/stc/cdeq.h6
-rw-r--r--include/stc/clist.h6
-rw-r--r--include/stc/cmap.h6
-rw-r--r--include/stc/cpque.h7
-rw-r--r--include/stc/csmap.h6
-rw-r--r--include/stc/cstack.h3
-rw-r--r--include/stc/cvec.h5
33 files changed, 106 insertions, 145 deletions
diff --git a/README.md b/README.md
index 3fc26682..02f4b02c 100644
--- a/README.md
+++ b/README.md
@@ -146,12 +146,12 @@ int main(void) {
c_auto (csmap_int, map)
{
// add some elements to each container
- c_emplace(cset_int, set, {10, 20, 30});
- c_emplace(cvec_pnt, vec, { {10, 1}, {20, 2}, {30, 3} });
- c_emplace(cdeq_int, deq, {10, 20, 30});
- c_emplace(clist_int, lst, {10, 20, 30});
- c_emplace(cstack_int, stk, {10, 20, 30});
- c_emplace(csmap_int, map, { {20, 2}, {10, 1}, {30, 3} });
+ c_apply(cset_int, insert, &set, {10, 20, 30});
+ c_apply(cvec_pnt, push_back, &vec, { {10, 1}, {20, 2}, {30, 3} });
+ c_apply(cdeq_int, push_back, &deq, {10, 20, 30});
+ c_apply(clist_int, push_back, &lst, {10, 20, 30});
+ c_apply(cstack_int, push, &stk, {10, 20, 30});
+ c_apply_pair(csmap_int, insert, &map, { {20, 2}, {10, 1}, {30, 3} });
// add one more element to each container
cset_int_insert(&set, 40);
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md
index 75ebae2f..8e8cbb28 100644
--- a/docs/ccommon_api.md
+++ b/docs/ccommon_api.md
@@ -90,7 +90,7 @@ int main()
#define i_key int
#include <stc/csset.h>
...
-c_emplace(csset_x, set, {23, 3, 7, 5, 12});
+c_apply(csset_x, insert, &set, {23, 3, 7, 5, 12});
c_foreach (i, csset_x, set)
printf(" %d", *i.ref);
// 3 5 7 12 23
@@ -122,11 +122,11 @@ c_forrange (i, int, 30, 0, -5) printf(" %d", i);
// 30 25 20 15 10 5
```
-### c_var, c_emplace
-**c_var** declares and initializes any container with an array of elements. **c_emplace** adds elements to any existing container:
+### c_apply, c_apply_pair
+**c_apply** will apply a method on an existing container with the given array elements:
```c
-c_var (cvec_i, vec, {1, 2, 3}); // declare and emplace
-c_emplace(cvec_i, vec, {4, 5, 6}); // adds to existing vec
+c_apply (cvec_i, push_back, &vec, {1, 2, 3}); // apply multiple push_backs
+c_apply_pair(cmap_i, insert, &map, { {4, 5}, {6, 7} }); // inserts to existing map
```
### c_new, c_new_n, c_del, c_make
diff --git a/docs/cdeq_api.md b/docs/cdeq_api.md
index ea6f176e..bacb2f86 100644
--- a/docs/cdeq_api.md
+++ b/docs/cdeq_api.md
@@ -107,7 +107,7 @@ int main() {
printf(" %d", *i.ref);
puts("");
- c_emplace(cdeq_i, q, {1, 4, 5, 22, 33, 2});
+ c_apply(cdeq_i, push_back, &q, {1, 4, 5, 22, 33, 2});
c_foreach (i, cdeq_i, q)
printf(" %d", *i.ref);
puts("");
diff --git a/docs/clist_api.md b/docs/clist_api.md
index d6be8bfc..e1b8f0b1 100644
--- a/docs/clist_api.md
+++ b/docs/clist_api.md
@@ -56,7 +56,6 @@ void clist_X_pop_front(clist_X* self);
void clist_X_push_back(clist_X* self, i_val value); // note: no pop_back().
void clist_X_emplace_back(clist_X* self, i_valraw raw);
-void clist_X_emplace_items(clist_X *self, const clist_X_rawvalue_t arr[], size_t n);
clist_X_iter_t clist_X_insert(clist_X* self, clist_X_iter_t it, i_val value); // return iter to new elem
clist_X_iter_t clist_X_emplace(clist_X* self, clist_X_iter_t it, i_valraw raw);
@@ -103,7 +102,8 @@ Interleave *push_front()* / *push_back()* then *sort()*:
#include <stdio.h>
int main() {
- c_var (clist_d, list, {
+ clist_d list = clist_d_init();
+ c_apply(clist_d, push_back, &list, {
10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0
});
@@ -143,7 +143,8 @@ Use of *erase_at()* and *erase_range()*:
int main ()
{
- c_var (clist_i, L, {10, 20, 30, 40, 50});
+ clist_i L = clist_i_init();
+ c_apply(clist_i, push_back, &L, {10, 20, 30, 40, 50});
// 10 20 30 40 50
clist_i_iter_t it = clist_i_begin(&L); // ^
clist_i_next(&it);
@@ -178,8 +179,8 @@ Splice `[30, 40]` from *L2* into *L1* before `3`:
int main() {
c_auto (clist_i, L1, L2)
{
- c_emplace(clist_i, L1, {1, 2, 3, 4, 5});
- c_emplace(clist_i, L2, {10, 20, 30, 40, 50});
+ c_apply(clist_i, push_back, &L1, {1, 2, 3, 4, 5});
+ c_apply(clist_i, push_back, &L2, {10, 20, 30, 40, 50});
clist_i_iter_t i = clist_i_advance(clist_i_begin(&L1), 2);
clist_i_iter_t j1 = clist_i_advance(clist_i_begin(&L2), 2), j2 = clist_i_advance(j1, 2);
diff --git a/docs/cmap_api.md b/docs/cmap_api.md
index 401e3cec..08f551e6 100644
--- a/docs/cmap_api.md
+++ b/docs/cmap_api.md
@@ -65,7 +65,6 @@ cmap_X_result_t cmap_X_put(cmap_X* self, i_key key, i_val mapped);
cmap_X_result_t cmap_X_emplace(cmap_X* self, i_keyraw rkey, i_valraw rmapped); // no change if rkey in map
cmap_X_result_t cmap_X_emplace_or_assign(cmap_X* self, i_keyraw rkey, i_valraw rmapped); // always update rmapped
-void cmap_X_emplace_items(cmap_X* self, const cmap_X_rawvalue_t arr[], size_t n);
size_t cmap_X_erase(cmap_X* self, i_keyraw rkey); // return 0 or 1
cmap_X_iter_t cmap_X_erase_at(cmap_X* self, cmap_X_iter_t it); // return iter after it
@@ -124,7 +123,8 @@ void c_default_del(Type* val); // d
int main()
{
// Create an unordered_map of three strings (that map to strings)
- c_var (cmap_str, u, {
+ cmap_str u = cmap_str_init();
+ c_apply_pair(cmap_str, emplace, &u, {
{"RED", "#FF0000"},
{"GREEN", "#00FF00"},
{"BLUE", "#0000FF"}
@@ -171,7 +171,7 @@ int main()
uint32_t col = 0xcc7744ff;
cmap_id idnames = cmap_id_init();
- c_emplace(cmap_id, idnames, { {100, "Red"}, {110, "Blue"} });
+ c_apply_pair(cmap_id, emplace, &idnames, { {100, "Red"}, {110, "Blue"} });
/* replace existing mapped value: */
cmap_id_emplace_or_assign(&idnames, 110, "White");
diff --git a/docs/cpque_api.md b/docs/cpque_api.md
index 0a4f7412..3b940648 100644
--- a/docs/cpque_api.md
+++ b/docs/cpque_api.md
@@ -36,7 +36,6 @@ const cpque_X_value_t* cpque_X_top(const cpque_X* self);
void cpque_X_push(cpque_X* self, cpque_X_value_t value);
void cpque_X_emplace(cpque_X* self, cpque_X_rawvalue_t raw);
-void cpque_X_emplace_items(cpque_X *self, const cpque_X_rawvalue_t arr[], size_t n);
void cpque_X_pop(cpque_X* self);
void cpque_X_erase_at(cpque_X* self, size_t idx);
@@ -74,7 +73,7 @@ int main()
// Push ten million random numbers to priority queue, plus some negative ones.
c_forrange (N)
cpque_i_push(&heap, stc64_uniform(&rng, &dist));
- c_emplace(cpque_i, heap, {-231, -32, -873, -4, -343});
+ c_apply(cpque_i, push, &heap, {-231, -32, -873, -4, -343});
// Extract and display the fifty smallest.
c_forrange (50) {
diff --git a/docs/cqueue_api.md b/docs/cqueue_api.md
index c6db0411..d5843614 100644
--- a/docs/cqueue_api.md
+++ b/docs/cqueue_api.md
@@ -36,7 +36,6 @@ cqueue_X_value_t* cqueue_X_back(const cqueue_X* self);
void cqueue_X_push(cqueue_X* self, cqueue_X_value_t value);
void cqueue_X_emplace(cqueue_X* self, cqueue_X_rawvalue_t raw);
-void cqueue_X_emplace_items(cqueue_X *self, const cqueue_X_rawvalue_t arr[], size_t n);
void cqueue_X_pop(cqueue_X* self);
diff --git a/docs/cset_api.md b/docs/cset_api.md
index 22e65a5e..d6c4ab80 100644
--- a/docs/cset_api.md
+++ b/docs/cset_api.md
@@ -46,7 +46,6 @@ cset_X_iter_t cset_X_find(const cset_X* self, i_keyraw rkey);
cset_X_result_t cset_X_insert(cset_X* self, i_key key);
cset_X_result_t cset_X_emplace(cset_X* self, i_keyraw rkey);
-void cset_X_emplace_items(cset_X* self, const i_keyraw arr[], size_t n);
size_t cset_X_erase(cset_X* self, i_keyraw rkey); // return 0 or 1
cset_X_iter_t cset_X_erase_at(cset_X* self, cset_X_iter_t it); // return iter after it
@@ -80,29 +79,28 @@ cset_X_value_t cset_X_value_clone(cset_X_value_t val);
int main ()
{
- cset_str first = cset_str_init(); // empty
- c_var (cset_str, second, {"red", "green", "blue"});
- c_var (cset_str, third, {"orange", "pink", "yellow"});
-
- cset_str fourth = cset_str_init();
- cset_str_emplace(&fourth, "potatoes");
- cset_str_emplace(&fourth, "milk");
- cset_str_emplace(&fourth, "flour");
-
- cset_str fifth = cset_str_clone(second);
- c_foreach (i, cset_str, third)
- cset_str_emplace(&fifth, i.ref->str);
- c_foreach (i, cset_str, fourth)
- cset_str_emplace(&fifth, i.ref->str);
-
- c_del(cset_str, &first, &second, &third, &fourth);
-
- printf("fifth contains:\n\n");
- c_foreach (i, cset_str, fifth)
- printf("%s\n", i.ref->str);
-
- cset_str_del(&fifth);
- return 0;
+ c_auto (cset_str, fifth)
+ {
+ c_auto (cset_str, first, second)
+ c_auto (cset_str, third, fourth)
+ {
+ c_apply(cset_str, emplace, &second, {"red", "green", "blue"});
+ c_apply(cset_str, emplace, &third, {"orange", "pink", "yellow"});
+
+ cset_str_emplace(&fourth, "potatoes");
+ cset_str_emplace(&fourth, "milk");
+ cset_str_emplace(&fourth, "flour");
+
+ fifth = cset_str_clone(second);
+ c_foreach (i, cset_str, third)
+ cset_str_emplace(&fifth, i.ref->str);
+ c_foreach (i, cset_str, fourth)
+ cset_str_emplace(&fifth, i.ref->str);
+ }
+ printf("fifth contains:\n\n");
+ c_foreach (i, cset_str, fifth)
+ printf("%s\n", i.ref->str);
+ }
}
```
Output:
diff --git a/docs/csmap_api.md b/docs/csmap_api.md
index 1a7ed78c..c6adcea9 100644
--- a/docs/csmap_api.md
+++ b/docs/csmap_api.md
@@ -58,7 +58,6 @@ csmap_X_result_t csmap_X_put(csmap_X* self, i_key key, i_val mapped);
csmap_X_result_t csmap_X_emplace(csmap_X* self, i_keyraw rkey, i_valraw rmapped); // no change if rkey in map
csmap_X_result_t csmap_X_emplace_or_assign(csmap_X* self, i_keyraw rkey, i_valraw rmapped); // always update rmapped
-void csmap_X_emplace_items(csmap_X* self, const csmap_X_rawvalue_t arr[], size_t n);
size_t csmap_X_erase(csmap_X* self, i_keyraw rkey);
csmap_X_iter_t csmap_X_erase_at(csmap_X* self, csmap_X_iter_t it); // returns iter after it
@@ -96,7 +95,8 @@ csmap_X_rawvalue_t csmap_X_value_toraw(csmap_X_value_t* pval);
int main()
{
// Create an unordered_map of three strings (maps to string)
- c_var (csmap_str, colors, {
+ csmap_str, colors = csmap_str_init();
+ c_apply(csmap_str, emplace, &colors, {
{"RED", "#FF0000"},
{"GREEN", "#00FF00"},
{"BLUE", "#0000FF"}
@@ -140,7 +140,8 @@ This example uses a csmap with cstr as mapped value.
int main()
{
uint32_t col = 0xcc7744ff;
- c_var (csmap_id, idnames, {
+ csmap_id idnames = csmap_id_init();
+ c_apply(csmap_id, push_back, &idnames, {
{100, "Red"},
{110, "Blue"},
});
diff --git a/docs/csset_api.md b/docs/csset_api.md
index 2d6c6486..f7cf0dc4 100644
--- a/docs/csset_api.md
+++ b/docs/csset_api.md
@@ -41,7 +41,6 @@ csset_X_value_t* csset_X_find_it(const csset_X* self, i_keyraw rkey, csset_X_
csset_X_result_t csset_X_insert(csset_X* self, i_key key);
csset_X_result_t csset_X_emplace(csset_X* self, i_keyraw rkey);
-void csset_X_emplace_items(csset_X* self, const i_keyraw arr[], size_t n);
size_t csset_X_erase(csset_X* self, i_keyraw rkey);
csset_X_iter_t csset_X_erase_at(csset_X* self, csset_X_iter_t it); // return iter after it
@@ -75,29 +74,28 @@ csset_X_value_t csset_X_value_clone(csset_X_value_t val);
int main ()
{
- csset_str first = csset_str_init(); // empty
- c_var (csset_str, second, {"red", "green", "blue"});
- c_var (csset_str, third, {"orange", "pink", "yellow"});
-
- csset_str fourth = csset_str_init();
- csset_str_emplace(&fourth, "potatoes");
- csset_str_emplace(&fourth, "milk");
- csset_str_emplace(&fourth, "flour");
-
- csset_str fifth = csset_str_clone(second);
- c_foreach (i, csset_str, third)
- csset_str_emplace(&fifth, i.ref->str);
- c_foreach (i, csset_str, fourth)
- csset_str_emplace(&fifth, i.ref->str);
-
- c_del(csset_str, &first, &second, &third, &fourth);
-
- printf("fifth contains:\n\n");
- c_foreach (i, csset_str, fifth)
- printf("%s\n", i.ref->str);
-
- csset_str_del(&fifth);
- return 0;
+c_auto (csset_str, fifth)
+ {
+ c_auto (csset_str, first, second)
+ c_auto (csset_str, third, fourth)
+ {
+ c_apply(csset_str, emplace, &second, {"red", "green", "blue"});
+ c_apply(csset_str, emplace, &third, {"orange", "pink", "yellow"});
+
+ csset_str_emplace(&fourth, "potatoes");
+ csset_str_emplace(&fourth, "milk");
+ csset_str_emplace(&fourth, "flour");
+
+ fifth = csset_str_clone(second);
+ c_foreach (i, csset_str, third)
+ csset_str_emplace(&fifth, i.ref->str);
+ c_foreach (i, csset_str, fourth)
+ csset_str_emplace(&fifth, i.ref->str);
+ }
+ printf("fifth contains:\n\n");
+ c_foreach (i, csset_str, fifth)
+ printf("%s\n", i.ref->str);
+ }
}
```
Output:
diff --git a/docs/cstack_api.md b/docs/cstack_api.md
index cd230508..79b515c6 100644
--- a/docs/cstack_api.md
+++ b/docs/cstack_api.md
@@ -35,7 +35,6 @@ cstack_X_value_t* cstack_X_top(const cstack_X* self);
void cstack_X_push(cstack_X* self, cstack_X_value_t value);
void cstack_X_emplace(cstack_X* self, cstack_X_rawvalue_t raw);
-void cstack_X_emplace_items(cstack_X *self, const cstack_X_rawvalue_t arr[], size_t n);
void cstack_X_pop(cstack_X* self);
diff --git a/docs/cvec_api.md b/docs/cvec_api.md
index 3b1ff265..ee02950f 100644
--- a/docs/cvec_api.md
+++ b/docs/cvec_api.md
@@ -114,7 +114,7 @@ int main()
cvec_i_push_back(&vec, 13);
// Append a set of numbers
- c_emplace(cvec_i, vec, {7, 5, 16, 8});
+ c_apply(cvec_i, push_back, &vec, {7, 5, 16, 8});
printf("initial:");
c_foreach (k, cvec_i, vec) {
diff --git a/examples/advanced.c b/examples/advanced.c
index 9ec73aa7..70aef8e8 100644
--- a/examples/advanced.c
+++ b/examples/advanced.c
@@ -48,10 +48,10 @@ static inline VikingRaw viking_toRaw(const Viking* vk) {
int main()
{
c_autovar (cmap_vk vikings = cmap_vk_init(), cmap_vk_del(&vikings)) {
- c_emplace(cmap_vk, vikings, {
- { {"Einar", "Norway"}, 20},
- { {"Olaf", "Denmark"}, 24},
- { {"Harald", "Iceland"}, 12},
+ c_apply_pair(cmap_vk, emplace, &vikings, {
+ {{"Einar", "Norway"}, 20},
+ {{"Olaf", "Denmark"}, 24},
+ {{"Harald", "Iceland"}, 12},
});
VikingRaw bjorn = {"Bjorn", "Sweden"};
cmap_vk_emplace_or_assign(&vikings, bjorn, 10);
diff --git a/examples/cpque.c b/examples/cpque.c
index 15bc2daa..17447341 100644
--- a/examples/cpque.c
+++ b/examples/cpque.c
@@ -42,16 +42,15 @@ int main()
{
c_forrange (n, c_arraylen(data))
cpque_imax_push(&q, n);
-
print_cpque_imax(q);
- cpque_imin_emplace_items(&q2, data, c_arraylen(data));
+ c_forrange (i, c_arraylen(data))
+ cpque_imin_push(&q2, data[i]);
print_cpque_imin(q2);
// Using imix_less to compare elements.
c_forrange (n, c_arraylen(data))
cpque_imix_push(&q3, n);
-
print_cpque_imix(q3);
}
} \ No newline at end of file
diff --git a/examples/csmap_erase.c b/examples/csmap_erase.c
index c8ecb5b1..66b45185 100644
--- a/examples/csmap_erase.c
+++ b/examples/csmap_erase.c
@@ -36,8 +36,8 @@ int main()
c_auto (csmap_my, m2)
{
- // Fill in some data to test with, one at a time, using c_emplace()
- c_emplace(csmap_my, m2, {
+ // Fill in some data to test with, one at a time, using c_apply_pair()
+ c_apply_pair(csmap_my, emplace, &m2, {
{10, "Bob"},
{11, "Rob"},
{12, "Robert"},
diff --git a/examples/csmap_find.c b/examples/csmap_find.c
index 55f7c23f..1b3320c9 100644
--- a/examples/csmap_find.c
+++ b/examples/csmap_find.c
@@ -46,7 +46,7 @@ int main()
c_auto (csmap_istr, m1)
c_auto (cvec_istr, v)
{
- c_emplace(csmap_istr, m1, { { 40, "Zr" }, { 45, "Rh" } });
+ c_apply_pair(csmap_istr, emplace, &m1, {{40, "Zr"}, {45, "Rh"}});
puts("The starting map m1 is (key, value):");
print_collection_csmap_istr(m1);
diff --git a/examples/csmap_insert.c b/examples/csmap_insert.c
index 1bb47697..ede1e5f0 100644
--- a/examples/csmap_insert.c
+++ b/examples/csmap_insert.c
@@ -74,10 +74,10 @@ int main()
c_foreach (e, cvec_ii, v) printf("(%d, %d) ", e.ref->first, e.ref->second);
puts("");
- csmap_ii_emplace_items(&m2, v.data, cvec_ii_size(v));
+ c_foreach (e, cvec_ii, v) csmap_ii_put(&m2, e.ref->first, e.ref->second);
puts("The modified key and mapped values of m2 are:");
- c_foreach (e, cvec_ii, v) printf("(%d, %d) ", e.ref->first, e.ref->second);
+ c_foreach (e, csmap_ii, m2) printf("(%d, %d) ", e.ref->first, e.ref->second);
puts("\n");
}
@@ -99,7 +99,7 @@ int main()
c_auto (csmap_ii, m4) {
// Insert the elements from an initializer_list
- c_emplace(csmap_ii, m4, { { 4, 44 }, { 2, 22 }, { 3, 33 }, { 1, 11 }, { 5, 55 } });
+ c_apply_pair(csmap_ii, insert, &m4, { { 4, 44 }, { 2, 22 }, { 3, 33 }, { 1, 11 }, { 5, 55 } });
puts("After initializer_list insertion, m4 contains:");
print_ii(m4);
puts("");
diff --git a/examples/csset_erase.c b/examples/csset_erase.c
index c32bf70c..df9b3d54 100644
--- a/examples/csset_erase.c
+++ b/examples/csset_erase.c
@@ -7,7 +7,7 @@ int main()
{
c_auto (csset_int, set)
{
- c_emplace(csset_int, set, {30, 20, 80, 40, 60, 90, 10, 70, 50});
+ c_apply(csset_int, insert, &set, {30, 20, 80, 40, 60, 90, 10, 70, 50});
c_foreach (k, csset_int, set)
printf(" %d", *k.ref);
puts("");
diff --git a/examples/inits.c b/examples/inits.c
index 64d1e970..47d01dac 100644
--- a/examples/inits.c
+++ b/examples/inits.c
@@ -47,7 +47,7 @@ int main(void)
// CVEC PRIORITY QUEUE
cpque_f_make_heap(&floats);
- c_emplace(cpque_f, floats, {40.0f, 20.0f, 50.0f, 30.0f, 10.0f});
+ c_apply(cpque_f, push, &floats, {40.0f, 20.0f, 50.0f, 30.0f, 10.0f});
puts("\npop and show high priorites first:");
while (! cpque_f_empty(floats)) {
@@ -73,7 +73,7 @@ int main(void)
// CMAP CNT
c_auto (cmap_cnt, countries) {
- c_emplace(cmap_cnt, countries, {
+ c_apply_pair(cmap_cnt, emplace, &countries, {
{"Norway", 100},
{"Denmark", 50},
{"Iceland", 10},
@@ -96,7 +96,7 @@ int main(void)
// CVEC PAIR
c_auto (cvec_ip, pairs1) {
- c_emplace (cvec_ip, pairs1, {{5, 6}, {3, 4}, {1, 2}, {7, 8}});
+ c_apply(cvec_ip, push_back, &pairs1, {{5, 6}, {3, 4}, {1, 2}, {7, 8}});
cvec_ip_sort(&pairs1);
c_foreach (i, cvec_ip, pairs1)
@@ -107,7 +107,7 @@ int main(void)
// CLIST PAIR
c_auto (clist_ip, pairs2) {
- c_emplace(clist_ip, pairs2, {{5, 6}, {3, 4}, {1, 2}, {7, 8}});
+ c_apply(clist_ip, push_back, &pairs2, {{5, 6}, {3, 4}, {1, 2}, {7, 8}});
clist_ip_sort(&pairs2);
c_foreach (i, clist_ip, pairs2)
diff --git a/examples/list.c b/examples/list.c
index ab5c70e2..94ee091f 100644
--- a/examples/list.c
+++ b/examples/list.c
@@ -36,7 +36,7 @@ int main() {
puts("");
clist_fx_clear(&list);
- c_emplace(clist_fx, list, {10, 20, 30, 40, 30, 50});
+ c_apply(clist_fx, push_back, &list, {10, 20, 30, 40, 30, 50});
c_foreach (i, clist_fx, list) printf(" %g", *i.ref);
puts("");
diff --git a/examples/list_erase.c b/examples/list_erase.c
index 9a3df2f6..db05fb42 100644
--- a/examples/list_erase.c
+++ b/examples/list_erase.c
@@ -9,7 +9,7 @@ int main ()
{
c_autovar (clist_i L = clist_i_init(), clist_i_del(&L))
{
- c_emplace(clist_i, L, {10, 20, 30, 40, 50});
+ c_apply(clist_i, push_back, &L, {10, 20, 30, 40, 50});
// 10 20 30 40 50
clist_i_iter_t it = clist_i_begin(&L); // ^
clist_i_next(&it);
diff --git a/examples/list_splice.c b/examples/list_splice.c
index 997c1cc3..425a344a 100644
--- a/examples/list_splice.c
+++ b/examples/list_splice.c
@@ -17,8 +17,8 @@ int main ()
{
c_auto (clist_i, list1, list2)
{
- c_emplace(clist_i, list1, {1, 2, 3, 4, 5});
- c_emplace(clist_i, list2, {10, 20, 30, 40, 50});
+ c_apply(clist_i, push_back, &list1, {1, 2, 3, 4, 5});
+ c_apply(clist_i, push_back, &list2, {10, 20, 30, 40, 50});
print_ilist("list1:", list1);
print_ilist("list2:", list2);
diff --git a/examples/phonebook.c b/examples/phonebook.c
index b7d3faba..640aaec3 100644
--- a/examples/phonebook.c
+++ b/examples/phonebook.c
@@ -42,14 +42,14 @@ int main(int argc, char **argv)
c_static_assert(sizeof argc == 4);
c_auto (cset_str, names) {
- c_emplace (cset_str, names, {"Hello", "Cool", "True"});
+ c_apply(cset_str, emplace, &names, {"Hello", "Cool", "True"});
c_foreach (i, cset_str, names) printf("%s ", i.ref->str);
puts("");
}
bool erased;
c_auto (cmap_str, phone_book) {
- c_emplace (cmap_str, phone_book, {
+ c_apply_pair (cmap_str, emplace, &phone_book, {
{"Lilia Friedman", "(892) 670-4739"},
{"Tariq Beltran", "(489) 600-7575"},
{"Laiba Juarez", "(303) 885-5692"},
diff --git a/examples/priority.c b/examples/priority.c
index 8ca02409..03bd1a03 100644
--- a/examples/priority.c
+++ b/examples/priority.c
@@ -20,7 +20,7 @@ int main() {
cpque_i_push(&heap, stc64_uniform(&rng, &dist));
// push some negative numbers too.
- c_emplace(cpque_i, heap, {-231, -32, -873, -4, -343});
+ c_apply(cpque_i, push, &heap, {-231, -32, -873, -4, -343});
c_forrange (N)
cpque_i_push(&heap, stc64_uniform(&rng, &dist));
diff --git a/examples/words.c b/examples/words.c
index 7ab6d026..87327d71 100644
--- a/examples/words.c
+++ b/examples/words.c
@@ -14,7 +14,7 @@ int main1()
c_auto (cvec_str, words)
c_auto (cmap_strn, word_map)
{
- c_emplace (cvec_str, words, {
+ c_apply(cvec_str, emplace_back, &words, {
"this", "sentence", "is", "not", "a", "sentence",
"this", "sentence", "is", "a", "hoax"
});
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 69afb2bd..2a1bea72 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -156,12 +156,18 @@ STC_API uint64_t c_default_hash(const void *key, size_t len);
*b = (n)*sizeof *b > (BYTES) ? c_new_n(type, n) : _c_b \
; b; b != _c_b ? c_free(b) : (void)0, b = NULL)
-#define c_var(CX, c, ...) \
- CX c = CX##_init(); c_emplace(CX, c, __VA_ARGS__)
+#define c_apply(CX, method, cx, ...) do { \
+ const CX##_rawvalue_t _c_arr[] = __VA_ARGS__; \
+ CX* _c_cx = (cx); \
+ for (size_t _c_i = 0; _c_i < c_arraylen(_c_arr); ++_c_i) \
+ CX##_##method(_c_cx, _c_arr[_c_i]); \
+} while (0)
-#define c_emplace(CX, cx, ...) do { \
+#define c_apply_pair(CX, method, cx, ...) do { \
const CX##_rawvalue_t _c_arr[] = __VA_ARGS__; \
- CX##_emplace_items(&(cx), _c_arr, c_arraylen(_c_arr)); \
+ CX* _c_cx = (cx); \
+ for (size_t _c_i = 0; _c_i < c_arraylen(_c_arr); ++_c_i) \
+ CX##_##method(_c_cx, _c_arr[_c_i].first, _c_arr[_c_i].second); \
} while (0)
#define c_del(CX, ...) do { \
diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h
index 5dec0f3c..41f8cea8 100644
--- a/include/stc/cdeq.h
+++ b/include/stc/cdeq.h
@@ -99,12 +99,6 @@ cx_memb(_shrink_to_fit)(Self *self) {
cx_memb(_del)(self); *self = cx;
}
-STC_INLINE void
-cx_memb(_emplace_items)(Self *self, const cx_rawvalue_t arr[], size_t n) {
- for (size_t i = 0; i < n; ++i)
- cx_memb(_push_back)(self, i_valfrom(arr[i]));
-}
-
#ifndef i_queue
STC_INLINE cx_value_t* cx_memb(_emplace_front)(Self* self, i_valraw raw) {
diff --git a/include/stc/clist.h b/include/stc/clist.h
index e123200f..7678b540 100644
--- a/include/stc/clist.h
+++ b/include/stc/clist.h
@@ -98,7 +98,6 @@ STC_API void cx_memb(_del)(Self* self);
STC_API cx_value_t* cx_memb(_push_back)(Self* self, i_val value);
STC_API cx_value_t* cx_memb(_push_front)(Self* self, i_val value);
STC_API cx_iter_t cx_memb(_insert)(Self* self, cx_iter_t it, i_val value);
-STC_API void cx_memb(_emplace_items)(Self *self, const cx_rawvalue_t arr[], size_t n);
STC_API cx_iter_t cx_memb(_erase_at)(Self* self, cx_iter_t it);
STC_API cx_iter_t cx_memb(_erase_range)(Self* self, cx_iter_t it1, cx_iter_t it2);
STC_API size_t cx_memb(_remove)(Self* self, i_valraw val);
@@ -209,11 +208,6 @@ cx_memb(_push_front)(Self* self, i_val value) {
return &entry->value;
}
-STC_DEF void
-cx_memb(_emplace_items)(Self *self, const cx_rawvalue_t arr[], size_t n) {
- for (size_t i=0; i<n; ++i) cx_memb(_push_back)(self, i_valfrom(arr[i]));
-}
-
STC_DEF cx_iter_t
cx_memb(_insert)(Self* self, cx_iter_t it, i_val value) {
cx_node_t* node = it.ref ? it.prev : self->last;
diff --git a/include/stc/cmap.h b/include/stc/cmap.h
index 763764b7..5a55c3df 100644
--- a/include/stc/cmap.h
+++ b/include/stc/cmap.h
@@ -152,12 +152,6 @@ cx_memb(_emplace)(Self* self, i_keyraw rkey cx_MAP_ONLY(, i_valraw rmapped)) {
return _res;
}
-STC_INLINE void
-cx_memb(_emplace_items)(Self* self, const cx_rawvalue_t arr[], size_t n) {
- for (size_t i=0; i<n; ++i) cx_SET_ONLY( cx_memb(_emplace)(self, arr[i]); )
- cx_MAP_ONLY( cx_memb(_emplace)(self, arr[i].first, arr[i].second); )
-}
-
STC_INLINE cx_result_t
cx_memb(_insert)(Self* self, i_key _key cx_MAP_ONLY(, i_val _mapped)) {
cx_result_t _res = cx_memb(_insert_entry_)(self, i_keyto(&_key));
diff --git a/include/stc/cpque.h b/include/stc/cpque.h
index 6819948f..7a81d486 100644
--- a/include/stc/cpque.h
+++ b/include/stc/cpque.h
@@ -41,7 +41,6 @@ typedef i_valraw cx_rawvalue_t;
STC_API void cx_memb(_make_heap)(Self* self);
STC_API void cx_memb(_erase_at)(Self* self, size_t idx);
STC_API void cx_memb(_push)(Self* self, cx_value_t value);
-STC_API void cx_memb(_emplace_items)(Self *self, const cx_rawvalue_t arr[], size_t n);
STC_API Self cx_memb(_clone)(Self q);
STC_INLINE Self cx_memb(_init)(void)
@@ -152,12 +151,6 @@ cx_memb(_push)(Self* self, cx_value_t value) {
if (c != n) arr[c] = value;
}
-STC_DEF void
-cx_memb(_emplace_items)(Self *self, const cx_rawvalue_t arr[], size_t n) {
- for (size_t i = 0; i < n; ++i)
- cx_memb(_push)(self, i_valfrom(arr[i]));
-}
-
#endif
#include "template.h"
#define CPQUE_H_INCLUDED \ No newline at end of file
diff --git a/include/stc/csmap.h b/include/stc/csmap.h
index 204a6bb3..8a172ad4 100644
--- a/include/stc/csmap.h
+++ b/include/stc/csmap.h
@@ -178,12 +178,6 @@ cx_memb(_emplace)(Self* self, i_keyraw rkey cx_MAP_ONLY(, i_valraw rmapped)) {
return res;
}
-STC_INLINE void
-cx_memb(_emplace_items)(Self* self, const cx_rawvalue_t arr[], size_t n) {
- for (size_t i=0; i<n; ++i) cx_SET_ONLY( cx_memb(_emplace)(self, arr[i]); )
- cx_MAP_ONLY( cx_memb(_emplace)(self, arr[i].first, arr[i].second); )
-}
-
STC_INLINE cx_result_t
cx_memb(_insert)(Self* self, i_key key cx_MAP_ONLY(, i_val mapped)) {
cx_result_t res = cx_memb(_insert_entry_)(self, i_keyto(&key));
diff --git a/include/stc/cstack.h b/include/stc/cstack.h
index 7543fb4f..2aaff4d9 100644
--- a/include/stc/cstack.h
+++ b/include/stc/cstack.h
@@ -91,9 +91,6 @@ STC_INLINE void cx_memb(_copy)(Self *self, Self other) {
cx_memb(_del)(self); *self = cx_memb(_clone)(other);
}
-STC_INLINE void cx_memb(_emplace_items)(Self *self, const cx_rawvalue_t arr[], size_t n)
- { for (size_t i = 0; i < n; ++i) cx_memb(_push)(self, i_valfrom(arr[i])); }
-
STC_INLINE i_val cx_memb(_value_clone)(cx_value_t val)
{ return i_valfrom(i_valto(&val)); }
diff --git a/include/stc/cvec.h b/include/stc/cvec.h
index 3dc7b4c1..d7f74fe9 100644
--- a/include/stc/cvec.h
+++ b/include/stc/cvec.h
@@ -172,11 +172,6 @@ STC_INLINE cx_iter_t
cx_memb(_emplace_range)(Self* self, cx_iter_t it, cx_iter_t it1, cx_iter_t it2) {
return cx_memb(_insert_range_p)(self, it.ref, it1.ref, it2.ref, true);
}
-STC_INLINE void
-cx_memb(_emplace_items)(Self *self, const cx_rawvalue_t arr[], size_t n) {
- cx_memb(_emplace_range_p)(self, self->data + cvec_rep_(self)->size, arr, arr + n);
-}
-
STC_INLINE cx_iter_t
cx_memb(_erase)(Self* self, size_t idx) {
return cx_memb(_erase_range_p)(self, self->data + idx, self->data + idx + 1);