summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-04-07 00:42:38 +0200
committerTyge Løvset <[email protected]>2022-04-07 00:42:38 +0200
commit03e36c56d8f61a6cbf2ca124134915999594fc91 (patch)
tree475d3b0ed1acf9809ba7483d912d2f0bdb356c38 /include
parent3fea4e0b232f7371628944587e561626503fb5fb (diff)
downloadSTC-modified-03e36c56d8f61a6cbf2ca124134915999594fc91.tar.gz
STC-modified-03e36c56d8f61a6cbf2ca124134915999594fc91.zip
Partly reverted (auto defined _i_no_emplace): emplace functions only available when either i_valraw or i_keyraw was defined. Avoids potensial bugs.
Diffstat (limited to 'include')
-rw-r--r--include/stc/cdeq.h10
-rw-r--r--include/stc/clist.h3
-rw-r--r--include/stc/cmap.h7
-rw-r--r--include/stc/cpque.h2
-rw-r--r--include/stc/csmap.h9
-rw-r--r--include/stc/cstack.h3
-rw-r--r--include/stc/cvec.h5
-rw-r--r--include/stc/template.h5
8 files changed, 37 insertions, 7 deletions
diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h
index f9de31d2..93e181c4 100644
--- a/include/stc/cdeq.h
+++ b/include/stc/cdeq.h
@@ -52,8 +52,10 @@ STC_API void _cx_memb(_shrink_to_fit)(_cx_self *self);
#if !defined _i_no_clone
STC_API _cx_iter _cx_memb(_clone_range_p)(_cx_self* self, _cx_value* pos,
const _cx_value* p1, const _cx_value* p2);
+#if !defined _i_no_emplace
STC_API _cx_iter _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos,
const _cx_raw* p1, const _cx_raw* p2);
+#endif // _i_no_emplace
#endif // !_i_no_clone
#if !c_option(c_no_cmp)
@@ -68,9 +70,10 @@ STC_API _cx_iter _cx_memb(_insert_range_p)(_cx_self* self, _cx_value* pos
#if !defined _i_no_clone
STC_API _cx_self _cx_memb(_clone)(_cx_self cx);
-
+#if !defined _i_no_emplace
STC_INLINE _cx_value* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw)
{ return _cx_memb(_push_back)(self, i_valfrom(raw)); }
+#endif
STC_INLINE i_val _cx_memb(_value_clone)(i_val val)
{ return i_valfrom(i_valto(&val)); }
STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) {
@@ -141,7 +144,7 @@ _cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2) {
}
#if !defined _i_no_clone
-
+#if !defined _i_no_emplace
STC_INLINE _cx_iter
_cx_memb(_emplace_range)(_cx_self* self, _cx_iter it, _cx_iter it1, _cx_iter it2) {
return _cx_memb(_clone_range_p)(self, it.ref, it1.ref, it2.ref);
@@ -163,6 +166,7 @@ STC_INLINE _cx_iter
_cx_memb(_emplace_at)(_cx_self* self, _cx_iter it, i_valraw raw) {
return _cx_memb(_emplace_range_p)(self, it.ref, &raw, &raw + 1);
}
+#endif // _i_no_emplace
#endif // !_i_no_clone
#if !c_option(c_no_cmp)
@@ -372,6 +376,7 @@ _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2) {
}
#if !defined _i_no_clone
+#if !defined _i_no_emplace
STC_DEF _cx_iter
_cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, const _cx_raw* p1, const _cx_raw* p2) {
pos = _cx_memb(_insert_space_)(self, pos, p2 - p1);
@@ -379,6 +384,7 @@ _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, const _cx_raw* p1, co
for (; p1 != p2; ++p1) *pos++ = i_valfrom(*p1);
return it;
}
+#endif
STC_DEF _cx_iter
_cx_memb(_clone_range_p)(_cx_self* self, _cx_value* pos,
diff --git a/include/stc/clist.h b/include/stc/clist.h
index e035d830..5591c93a 100644
--- a/include/stc/clist.h
+++ b/include/stc/clist.h
@@ -115,7 +115,7 @@ _cx_memb(_copy)(_cx_self *self, _cx_self other) {
if (self->last == other.last) return;
_cx_memb(_drop)(self); *self = _cx_memb(_clone)(other);
}
-
+#if !defined _i_no_emplace
STC_INLINE _cx_value* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw)
{ return _cx_memb(_push_back)(self, i_valfrom(raw)); }
STC_INLINE _cx_value* _cx_memb(_emplace_front)(_cx_self* self, i_valraw raw)
@@ -123,6 +123,7 @@ STC_INLINE _cx_value* _cx_memb(_emplace_front)(_cx_self* self, i_valraw raw)
STC_INLINE _cx_iter _cx_memb(_emplace)(_cx_self* self, _cx_iter it, i_valraw raw)
{ return _cx_memb(_insert)(self, it, i_valfrom(raw)); }
#endif
+#endif
STC_INLINE _cx_self _cx_memb(_init)(void) { return c_make(_cx_self){NULL}; }
STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, size_t n) { return true; }
diff --git a/include/stc/cmap.h b/include/stc/cmap.h
index 9bc4d621..a8e23da5 100644
--- a/include/stc/cmap.h
+++ b/include/stc/cmap.h
@@ -111,8 +111,10 @@ STC_INLINE bool _cx_memb(_contains)(const _cx_self* self, i_keyraw rkey)
#ifndef _i_isset
#if !defined _i_no_clone
+ #if !defined _i_no_emplace
STC_API _cx_result _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped);
#endif
+ #endif
STC_API _cx_result _cx_memb(_insert_or_assign)(_cx_self* self, i_key _key, i_val _mapped);
STC_INLINE _cx_result /* short-form, like operator[]: */
@@ -140,7 +142,7 @@ _cx_memb(_value_clone)(_cx_value _val) {
_i_MAP_ONLY( _val.second = i_valfrom(i_valto(&_val.second)); )
return _val;
}
-
+#if !defined _i_no_emplace
STC_INLINE _cx_result
_cx_memb(_emplace)(_cx_self* self, i_keyraw rkey _i_MAP_ONLY(, i_valraw rmapped)) {
_cx_result _res = _cx_memb(_insert_entry_)(self, rkey);
@@ -150,6 +152,7 @@ _cx_memb(_emplace)(_cx_self* self, i_keyraw rkey _i_MAP_ONLY(, i_valraw rmapped)
}
return _res;
}
+#endif // !_i_no_emplace
#endif // !_i_no_clone
STC_INLINE _cx_raw
@@ -273,6 +276,7 @@ STC_DEF void _cx_memb(_clear)(_cx_self* self) {
}
#if !defined _i_no_clone
+ #if !defined _i_no_emplace
STC_DEF _cx_result
_cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped) {
_cx_result _res = _cx_memb(_insert_entry_)(self, rkey);
@@ -281,6 +285,7 @@ STC_DEF void _cx_memb(_clear)(_cx_self* self) {
_res.ref->second = i_valfrom(rmapped); return _res;
}
#endif
+ #endif
#endif
STC_DEF chash_bucket_t
diff --git a/include/stc/cpque.h b/include/stc/cpque.h
index 45a8828f..3fa561ed 100644
--- a/include/stc/cpque.h
+++ b/include/stc/cpque.h
@@ -98,9 +98,11 @@ STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) {
STC_INLINE i_val _cx_memb(_value_clone)(_cx_value val)
{ return i_valfrom(i_valto(&val)); }
+#if !defined _i_no_emplace
STC_INLINE void _cx_memb(_emplace)(_cx_self* self, _cx_raw raw)
{ _cx_memb(_push)(self, i_valfrom(raw)); }
#endif
+#endif
/* -------------------------- IMPLEMENTATION ------------------------- */
#if defined(_i_implement)
diff --git a/include/stc/csmap.h b/include/stc/csmap.h
index 9f8a3455..ea9e1984 100644
--- a/include/stc/csmap.h
+++ b/include/stc/csmap.h
@@ -97,8 +97,10 @@ typedef _i_SET_ONLY( i_keyraw )
STC_API _cx_self _cx_memb(_clone)(_cx_self tree);
STC_API void _cx_memb(_copy)(_cx_self *self, _cx_self other);
STC_API _cx_value _cx_memb(_value_clone)(_cx_value _val);
+#if !defined _i_no_emplace
STC_API _cx_result _cx_memb(_emplace)(_cx_self* self, i_keyraw rkey _i_MAP_ONLY(, i_valraw rmapped));
#endif
+#endif
STC_API _cx_self _cx_memb(_init)(void);
STC_API _cx_result _cx_memb(_insert)(_cx_self* self, i_key key _i_MAP_ONLY(, i_val mapped));
STC_API void _cx_memb(_drop)(_cx_self* self);
@@ -155,8 +157,10 @@ _cx_memb(_value_drop)(_cx_value* val) {
#ifndef _i_isset
#if !defined _i_no_clone
+ #if !defined _i_no_emplace
STC_API _cx_result _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped);
#endif
+ #endif
STC_API _cx_result _cx_memb(_insert_or_assign)(_cx_self* self, i_key key, i_val mapped);
STC_INLINE _cx_result
@@ -276,6 +280,7 @@ _cx_memb(_insert)(_cx_self* self, i_key key _i_MAP_ONLY(, i_val mapped)) {
}
#if !defined _i_no_clone
+ #if !defined _i_no_emplace
STC_DEF _cx_result
_cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped) {
_cx_result res = _cx_memb(_insert_entry_)(self, rkey);
@@ -284,6 +289,7 @@ _cx_memb(_insert)(_cx_self* self, i_key key _i_MAP_ONLY(, i_val mapped)) {
res.ref->second = i_valfrom(rmapped); return res;
}
#endif
+ #endif
#endif
STC_DEF _cx_value*
@@ -490,7 +496,7 @@ _cx_memb(_clone)(_cx_self tree) {
_csmap_rep(&clone)->size = _csmap_rep(&tree)->size;
return clone;
}
-
+#if !defined _i_no_emplace
STC_DEF _cx_result
_cx_memb(_emplace)(_cx_self* self, i_keyraw rkey _i_MAP_ONLY(, i_valraw rmapped)) {
_cx_result res = _cx_memb(_insert_entry_)(self, rkey);
@@ -500,6 +506,7 @@ _cx_memb(_emplace)(_cx_self* self, i_keyraw rkey _i_MAP_ONLY(, i_valraw rmapped)
}
return res;
}
+#endif // _i_no_emplace
#endif // !_i_no_clone
static void
diff --git a/include/stc/cstack.h b/include/stc/cstack.h
index 1d2b259d..bbf4613b 100644
--- a/include/stc/cstack.h
+++ b/include/stc/cstack.h
@@ -99,11 +99,12 @@ STC_INLINE const _cx_value* _cx_memb(_at)(const _cx_self* self, size_t idx)
{ assert(idx < self->size); return self->data + idx; }
#if !defined _i_no_clone
+#if !defined _i_no_emplace
STC_INLINE _cx_value* _cx_memb(_emplace)(_cx_self* self, _cx_raw raw)
{ return _cx_memb(_push)(self, i_valfrom(raw)); }
STC_INLINE _cx_value* _cx_memb(_emplace_back)(_cx_self* self, _cx_raw raw)
{ return _cx_memb(_push)(self, i_valfrom(raw)); }
-
+#endif
STC_INLINE _cx_self _cx_memb(_clone)(_cx_self v) {
_cx_self out = {(_cx_value *) c_malloc(v.size*sizeof(_cx_value)), v.size, v.size};
for (size_t i = 0; i < v.size; ++i, ++v.data) out.data[i] = i_valfrom(i_valto(v.data));
diff --git a/include/stc/cvec.h b/include/stc/cvec.h
index ec8e9164..81e5f7de 100644
--- a/include/stc/cvec.h
+++ b/include/stc/cvec.h
@@ -104,6 +104,7 @@ STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) {
_cx_memb(_drop)(self);
*self = _cx_memb(_clone)(other);
}
+#if !defined _i_no_emplace
STC_API _cx_iter _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos,
const _cx_raw* p1, const _cx_raw* p2);
STC_INLINE _cx_value* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw)
@@ -122,6 +123,7 @@ STC_INLINE _cx_iter
_cx_memb(_emplace_range)(_cx_self* self, _cx_iter it, _cx_iter it1, _cx_iter it2) {
return _cx_memb(_clone_range_p)(self, it.ref, it1.ref, it2.ref);
}
+#endif // !_i_no_emplace
#endif // !_i_no_clone
STC_INLINE size_t _cx_memb(_size)(_cx_self cx) { return cvec_rep_(&cx)->size; }
@@ -348,7 +350,7 @@ _cx_memb(_clone_range_p)(_cx_self* self, _cx_value* pos,
for (; p1 != p2; ++p1) *pos++ = i_valfrom(i_valto(p1));
return it;
}
-
+#if !defined _i_no_emplace
STC_DEF _cx_iter
_cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos,
const _cx_raw* p1, const _cx_raw* p2) {
@@ -357,6 +359,7 @@ _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos,
for (; p1 != p2; ++p1) *pos++ = i_valfrom(*p1);
return it;
}
+#endif
#endif // !_i_no_clone
#if !c_option(c_no_cmp)
diff --git a/include/stc/template.h b/include/stc/template.h
index 593a9313..b2dcebd8 100644
--- a/include/stc/template.h
+++ b/include/stc/template.h
@@ -150,6 +150,10 @@
#error "if i_valraw defined, i_valfrom (and often i_valto) must be defined"
#endif
+#if !defined i_keyraw && !defined i_valraw
+ #define _i_no_emplace
+#endif
+
#ifdef i_key
#ifdef _i_isset
#define i_val i_key
@@ -239,5 +243,6 @@
#undef _i_prefix
#undef _i_no_clone
+#undef _i_no_emplace
#undef _i_template
#endif