22#ifndef ESPRESSO_UTILS_BAG_HPP
23#define ESPRESSO_UTILS_BAG_HPP
25#include <boost/serialization/access.hpp>
26#include <boost/serialization/vector.hpp>
49template <
class T>
class Bag {
50 static_assert(std::is_swappable_v<T>);
53 using storage_type = std::vector<T>;
69 storage_type m_storage;
71 friend boost::serialization::access;
77 template <
class Archive>
void serialize(Archive &ar,
long int ) {
90 std::size_t
size()
const {
return m_storage.size(); }
96 bool empty()
const {
return m_storage.empty(); }
104 std::size_t
capacity()
const {
return m_storage.capacity(); }
109 std::size_t
max_size()
const {
return m_storage.max_size(); }
118 void reserve(std::size_t new_capacity) { m_storage.reserve(new_capacity); }
129 void resize(std::size_t new_size) { m_storage.resize(new_size); }
148 m_storage.push_back(v);
150 return m_storage.back();
154 m_storage.push_back(std::move(v));
156 return m_storage.back();
166 *it = std::move(m_storage.back());
168 m_storage.pop_back();
182 swap(lhs.m_storage, rhs.m_storage);
void reserve(std::size_t new_capacity)
Reserve storage.
const_iterator begin() const
std::size_t capacity() const
Capacity of the container.
T & insert(T &&v)
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend void swap(Bag &lhs, Bag &rhs)
Swap two Bags.
void clear()
Remove all elements form container.
bool empty() const
Is the container empty?
T & insert(T const &v)
Insert an element into the container.
iterator erase(iterator it)
Remove element from the list.
const_iterator end() const
std::size_t size() const
Number of elements in the container.
Bag()=default
Construct an empty container.
std::size_t max_size() const
Maximum number of elements the container can hold.
void resize(std::size_t new_size)
Resize container.