diff options
| author | Tyge Løvset <[email protected]> | 2023-01-19 19:27:07 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-01-19 19:27:07 +0100 |
| commit | 5aa48d538569463ffeda976d21f79edc5f276be4 (patch) | |
| tree | 6bbd87bc9e5041b2c3b69e14ec175536b8418630 /include/stc/csmap.h | |
| parent | 0c4c4f8bba17562735b67b2923cd23c773aa53a7 (diff) | |
| download | STC-modified-5aa48d538569463ffeda976d21f79edc5f276be4.tar.gz STC-modified-5aa48d538569463ffeda976d21f79edc5f276be4.zip | |
Add a from_n() method to containers (and put_n() to maps), to support new initialization.
Diffstat (limited to 'include/stc/csmap.h')
| -rw-r--r-- | include/stc/csmap.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/include/stc/csmap.h b/include/stc/csmap.h index e5df0fe2..75f10308 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -294,6 +294,22 @@ _cx_memb(_push)(_cx_self* self, _cx_value _val) { return _res; } +STC_INLINE void _cx_memb(_put_n)(_cx_self* self, const _cx_raw* raw, size_t n) { + while (n--) +#if defined _i_isset && defined i_no_emplace + _cx_memb(_insert)(self, *raw++); +#elif defined _i_isset + _cx_memb(_emplace)(self, *raw++); +#elif defined i_no_emplace + _cx_memb(_insert_or_assign)(self, raw->first, raw->second), ++raw; +#else + _cx_memb(_emplace_or_assign)(self, raw->first, raw->second), ++raw; +#endif +} + +STC_INLINE _cx_self _cx_memb(_from_n)(const _cx_raw* raw, size_t n) + { _cx_self cx = {0}; _cx_memb(_put_n)(&cx, raw, n); return cx; } + #ifndef _i_isset STC_DEF _cx_result _cx_memb(_insert_or_assign)(_cx_self* self, i_key _key, i_val _mapped) { |
