diff options
author | Colin Snover | 2016-02-03 13:51:16 -0600 |
---|---|---|
committer | Colin Snover | 2016-02-18 13:18:01 -0600 |
commit | 7d54f0aaaf1854e421ee0e8eac3292c7bc0db284 (patch) | |
tree | b0735335839815ffc3088fc95bc4fc8c4e4723e2 /common/array.h | |
parent | 1a542ae82c941353fb135aac8c0c2a0b4b6df3e7 (diff) | |
download | scummvm-rg350-7d54f0aaaf1854e421ee0e8eac3292c7bc0db284.tar.gz scummvm-rg350-7d54f0aaaf1854e421ee0e8eac3292c7bc0db284.tar.bz2 scummvm-rg350-7d54f0aaaf1854e421ee0e8eac3292c7bc0db284.zip |
COMMON: Add methods for inserting and erasing with iterators
This provides improved feature parity to Common::List and is used
in SCI32 engine.
Diffstat (limited to 'common/array.h')
-rw-r--r-- | common/array.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/common/array.h b/common/array.h index f240a9c2f5..db1a62ba34 100644 --- a/common/array.h +++ b/common/array.h @@ -141,6 +141,12 @@ public: insert_aux(_storage + idx, array.begin(), array.end()); } + /** + * Inserts element before pos. + */ + void insert(iterator pos, const T &element) { + insert_aux(pos, &element, &element + 1); + } T remove_at(size_type idx) { assert(idx < _size); @@ -187,6 +193,14 @@ public: _capacity = 0; } + iterator erase(iterator pos) { + copy(pos + 1, _storage + _size, pos); + _size--; + // We also need to destroy the last object properly here. + _storage[_size].~T(); + return pos; + } + bool empty() const { return (_size == 0); } |