summaryrefslogtreecommitdiff
path: root/lib/pack.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-05-01 18:14:49 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-05-01 18:14:49 +0100
commita6457aea04d1705f5b03f9c9e628bebbefdcf64c (patch)
tree8c944e698d8e1691561186ea18b9024e65225739 /lib/pack.h
parentAdd method to get GL buffer name of glContainer (diff)
downloadilt-a6457aea04d1705f5b03f9c9e628bebbefdcf64c.tar.bz2
ilt-a6457aea04d1705f5b03f9c9e628bebbefdcf64c.tar.xz
ilt-a6457aea04d1705f5b03f9c9e628bebbefdcf64c.zip
Add the pack container
Keeps its elements densely packed together without any interest in order
Diffstat (limited to 'lib/pack.h')
-rw-r--r--lib/pack.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/pack.h b/lib/pack.h
new file mode 100644
index 0000000..92c8b20
--- /dev/null
+++ b/lib/pack.h
@@ -0,0 +1,42 @@
+#pragma once
+
+#include <utility>
+
+template<typename T, template<typename... S> typename Container> class pack : protected Container<T> {
+public:
+ using Container<T>::Container;
+
+ using Container<T>::begin;
+ using Container<T>::end;
+ using Container<T>::rbegin;
+ using Container<T>::rend;
+ using Container<T>::cbegin;
+ using Container<T>::cend;
+ using Container<T>::crbegin;
+ using Container<T>::crend;
+ using Container<T>::clear;
+ using Container<T>::empty;
+ using Container<T>::size;
+ using Container<T>::capacity;
+ using Container<T>::shrink_to_fit;
+ using Container<T>::at;
+ using Container<T>::data;
+ using Container<T>::operator[];
+
+ template<typename... Ps>
+ decltype(auto)
+ emplace(Ps &&... ps)
+ {
+ return Container<T>::emplace_back(std::forward<Ps>(ps)...);
+ }
+
+ void
+ erase(typename Container<T>::iterator pos)
+ {
+ pos->~T();
+ if (&*pos != &Container<T>::back()) {
+ new (&*pos) T(std::move(Container<T>::back()));
+ }
+ Container<T>::pop_back();
+ }
+};