ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
Utils::Bag< T > Class Template Reference

Bag of elements. More...

#include <Bag.hpp>

Public Types

using value_type = T
 
using iterator = T *
 
using const_iterator = const T *
 
using pointer = T *
 
using reference = T &
 

Public Member Functions

 Bag ()=default
 Construct an empty container.
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
std::size_t size () const
 Number of elements in the container.
 
bool empty () const
 Is the container empty?
 
std::size_t capacity () const
 Capacity of the container.
 
std::size_t max_size () const
 Maximum number of elements the container can hold.
 
void reserve (std::size_t new_capacity)
 Reserve storage.
 
void resize (std::size_t new_size)
 Resize container.
 
void clear ()
 Remove all elements form container.
 
T & insert (T const &v)
 Insert an element into the container.
 
T & insert (T &&v)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
iterator erase (iterator it)
 Remove element from the list.
 

Friends

void swap (Bag &lhs, Bag &rhs)
 Swap two Bags.
 

Detailed Description

template<class T>
class Utils::Bag< T >

Bag of elements.

A bag is a container in which the elements do not have a fixed order. It can be considered an unordered variant of vector, and implements the Container named requirement specified in C++11.

Elements in the container do not have a stable position and removing elements can change the order of the other elements. The looser contract (compared to a vector) allows removing any element in the container in constant time.

Template Parameters
TElement type, needs to be Swappable.

Definition at line 49 of file Bag.hpp.

Member Typedef Documentation

◆ const_iterator

template<class T >
using Utils::Bag< T >::const_iterator = const T *

Definition at line 58 of file Bag.hpp.

◆ iterator

template<class T >
using Utils::Bag< T >::iterator = T *

Definition at line 57 of file Bag.hpp.

◆ pointer

template<class T >
using Utils::Bag< T >::pointer = T *

Definition at line 59 of file Bag.hpp.

◆ reference

template<class T >
using Utils::Bag< T >::reference = T &

Definition at line 60 of file Bag.hpp.

◆ value_type

template<class T >
using Utils::Bag< T >::value_type = T

Definition at line 56 of file Bag.hpp.

Constructor & Destructor Documentation

◆ Bag()

template<class T >
Utils::Bag< T >::Bag ( )
default

Construct an empty container.

Member Function Documentation

◆ begin() [1/2]

template<class T >
iterator Utils::Bag< T >::begin ( )
inline

Definition at line 82 of file Bag.hpp.

◆ begin() [2/2]

template<class T >
const_iterator Utils::Bag< T >::begin ( ) const
inline

Definition at line 84 of file Bag.hpp.

◆ capacity()

template<class T >
std::size_t Utils::Bag< T >::capacity ( ) const
inline

Capacity of the container.

Number of elements the container can at least hold without reallocating.

Definition at line 104 of file Bag.hpp.

◆ clear()

template<class T >
void Utils::Bag< T >::clear ( )
inline

Remove all elements form container.

Definition at line 134 of file Bag.hpp.

◆ empty()

template<class T >
bool Utils::Bag< T >::empty ( ) const
inline

Is the container empty?

Returns
True if there are no elements.

Definition at line 96 of file Bag.hpp.

Referenced by RegularDecomposition::resort().

◆ end() [1/2]

template<class T >
iterator Utils::Bag< T >::end ( )
inline

Definition at line 83 of file Bag.hpp.

References Utils::Bag< T >::size().

◆ end() [2/2]

template<class T >
const_iterator Utils::Bag< T >::end ( ) const
inline

Definition at line 85 of file Bag.hpp.

References Utils::Bag< T >::size().

◆ erase()

template<class T >
iterator Utils::Bag< T >::erase ( iterator  it)
inline

Remove element from the list.

Parameters
itIterator pointing to the element to remove.
Returns
An iterator past the element that was removed.

Definition at line 165 of file Bag.hpp.

◆ insert() [1/2]

template<class T >
T & Utils::Bag< T >::insert ( T &&  v)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 153 of file Bag.hpp.

◆ insert() [2/2]

template<class T >
T & Utils::Bag< T >::insert ( T const &  v)
inline

Insert an element into the container.

If before the call size() >= capacity(), this may reallocate, in which case all iterators into the container are invalidated. Otherwise only the end iterator is invalidated.

Parameters
vElement to add.
Returns
Reference to the added element.

Definition at line 147 of file Bag.hpp.

Referenced by RegularDecomposition::resort().

◆ max_size()

template<class T >
std::size_t Utils::Bag< T >::max_size ( ) const
inline

Maximum number of elements the container can hold.

Definition at line 109 of file Bag.hpp.

◆ reserve()

template<class T >
void Utils::Bag< T >::reserve ( std::size_t  new_capacity)
inline

Reserve storage.

Increase capacity to at least the specified value.

Parameters
new_capacityNew minimum capacity.

Definition at line 118 of file Bag.hpp.

◆ resize()

template<class T >
void Utils::Bag< T >::resize ( std::size_t  new_size)
inline

Resize container.

Newly added Ts are default-initialized. If the new size is larger than the capacity, all iterators into the container are invalidated.

Parameters
new_sizeSize to resize to.

Definition at line 129 of file Bag.hpp.

Referenced by prepare_ghost_cell().

◆ size()

template<class T >
std::size_t Utils::Bag< T >::size ( ) const
inline

Number of elements in the container.

Definition at line 90 of file Bag.hpp.

Referenced by Utils::Bag< T >::end(), Utils::Bag< T >::end(), and RegularDecomposition::resort().

Friends And Related Symbol Documentation

◆ swap

template<class T >
void swap ( Bag< T > &  lhs,
Bag< T > &  rhs 
)
friend

Swap two Bags.

Efficiently swap to bags by swapping their contained storage.

Definition at line 179 of file Bag.hpp.


The documentation for this class was generated from the following file: