summaryrefslogtreecommitdiff
path: root/lib/pack.h
blob: 92c8b20c7277a3e78f9f1c89dfc2cc26715141e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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();
	}
};