summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-04-22 12:44:57 +0200
committerTyge Løvset <[email protected]>2022-04-22 12:44:57 +0200
commitdd5551dec268da39ad1c5c66de014e4621d24748 (patch)
tree104de218168bddaee937e92c919e0459d35209fc /include
parent8f57f3d331de4cb4aa7d06862c2de3424eb1ba5b (diff)
downloadSTC-modified-dd5551dec268da39ad1c5c66de014e4621d24748.tar.gz
STC-modified-dd5551dec268da39ad1c5c66de014e4621d24748.zip
Changed API for c*map_X_push() to take a entry pair (c*map_X_value) argument instead of key + val.
Diffstat (limited to 'include')
-rw-r--r--include/stc/cmap.h6
-rw-r--r--include/stc/csmap.h13
2 files changed, 12 insertions, 7 deletions
diff --git a/include/stc/cmap.h b/include/stc/cmap.h
index 16041094..6cde2532 100644
--- a/include/stc/cmap.h
+++ b/include/stc/cmap.h
@@ -178,8 +178,10 @@ _cx_memb(_insert)(_cx_self* self, i_key _key _i_MAP_ONLY(, i_val _mapped)) {
}
STC_INLINE _cx_result
-_cx_memb(_push)(_cx_self* self, i_key _key _i_MAP_ONLY(, i_val _mapped)) {
- return _cx_memb(_insert)(self, _key _i_MAP_ONLY(, _mapped));
+_cx_memb(_push)(_cx_self* self, _cx_value _val) {
+ _cx_result _res = _cx_memb(_insert_entry_)(self, i_keyto(_i_keyref(&_val)));
+ if (_res.inserted) *_res.ref = _val; else _cx_memb(_value_drop)(&_val);
+ return _res;
}
STC_INLINE _cx_iter
diff --git a/include/stc/csmap.h b/include/stc/csmap.h
index 700aa4c2..25f66d79 100644
--- a/include/stc/csmap.h
+++ b/include/stc/csmap.h
@@ -104,6 +104,7 @@ STC_API _cx_result _cx_memb(_emplace)(_cx_self* self, i_keyraw rkey _i_MAP_
#endif // !_i_no_clone
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 _cx_result _cx_memb(_push)(_cx_self* self, _cx_value _val);
STC_API void _cx_memb(_drop)(_cx_self* self);
STC_API bool _cx_memb(_reserve)(_cx_self* self, size_t cap);
STC_API _cx_value* _cx_memb(_find_it)(const _cx_self* self, i_keyraw rkey, _cx_iter* out);
@@ -170,11 +171,6 @@ _cx_memb(_value_drop)(_cx_value* val) {
{ _cx_iter it; return &_cx_memb(_find_it)(self, rkey, &it)->second; }
#endif // !_i_isset
-STC_INLINE _cx_result
-_cx_memb(_push)(_cx_self* self, i_key _key _i_MAP_ONLY(, i_val _mapped)) {
- return _cx_memb(_insert)(self, _key _i_MAP_ONLY(, _mapped));
-}
-
STC_INLINE _cx_iter
_cx_memb(_find)(const _cx_self* self, i_keyraw rkey) {
_cx_iter it;
@@ -273,6 +269,13 @@ _cx_memb(_insert)(_cx_self* self, i_key key _i_MAP_ONLY(, i_val mapped)) {
return res;
}
+STC_DEF _cx_result
+_cx_memb(_push)(_cx_self* self, _cx_value _val) {
+ _cx_result _res = _cx_memb(_insert_entry_)(self, i_keyto(_i_keyref(&_val)));
+ if (_res.inserted) *_res.ref = _val; else _cx_memb(_value_drop)(&_val);
+ return _res;
+}
+
#ifndef _i_isset
STC_DEF _cx_result
_cx_memb(_insert_or_assign)(_cx_self* self, i_key key, i_val mapped) {