Template Class vector
Defined in File vector.hpp
Class Documentation
-
template<typename T, uint64_t Capacity>
class vector C++11 compatible vector implementation. We needed to do some adjustments in the API since we do not use exceptions and we require a data structure which can be located fully in the shared memory.
- Attention
Out of bounds access or accessing an empty vector can lead to a program termination!
Public Functions
-
vector() noexcept = default
creates an empty vector
-
vector(const uint64_t count, const T &value) noexcept
creates a vector with count copies of elements with value value
- Parameters:
count – [in] is the number copies which are inserted into the vector
value – [in] is the value which is inserted into the vector
-
vector(const uint64_t count) noexcept
creates a vector with count copies of elements constructed with the default constructor of T
- Parameters:
count – [in] is the number copies which are inserted into the vector
-
~vector() noexcept
destructs the vector and also calls the destructor of all contained elements
-
vector &operator=(const vector &rhs) noexcept
copy assignment. if the destination vector contains more elements than the source the remaining elements will be destructed
-
vector &operator=(vector &&rhs) noexcept
move assignment. if the destination vector contains more elements than the source the remaining elements will be destructed
-
iterator begin() noexcept
returns an iterator to the first element of the vector, if the vector is empty it returns the same iterator as end (the first iterator which is outside of the vector)
-
const_iterator begin() const noexcept
returns a const iterator to the first element of the vector, if the vector is empty it returns the same iterator as end (the first iterator which is outside of the vector)
-
iterator end() noexcept
returns an iterator to the element which comes after the last element (the first element which is outside of the vector)
-
const_iterator end() const noexcept
returns a const iterator to the element which comes after the last element (the first element which is outside of the vector)
-
const T *data() const noexcept
return the const pointer to the underlying array
- Returns:
const pointer to underlying array
-
T &at(const uint64_t index) noexcept
returns a reference to the element stored at index. the behavior
- Attention
Out of bounds access can lead to a program termination!
-
const T &at(const uint64_t index) const noexcept
returns a const reference to the element stored at index. the behavior is undefined if the element at index does not exist.
- Attention
Out of bounds access can lead to a program termination!
-
T &operator[](const uint64_t index) noexcept
returns a reference to the element stored at index. the behavior
- Attention
Out of bounds access can lead to a program termination!
-
const T &operator[](const uint64_t index) const noexcept
returns a const reference to the element stored at index. the behavior is undefined if the element at index does not exist.
- Attention
Out of bounds access can lead to a program termination!
-
T &front() noexcept
returns a reference to the first element; terminates if the vector is empty
- Attention
Accessing an empty vector can lead to a program termination!
- Returns:
reference to the first element
-
const T &front() const noexcept
returns a const reference to the first element; terminates if the vector is empty
- Attention
Accessing an empty vector can lead to a program termination!
- Returns:
const reference to the first element
-
T &back() noexcept
returns a reference to the last element; terminates if the vector is empty
- Attention
Accessing an empty vector can lead to a program termination!
- Returns:
reference to the last element
-
const T &back() const noexcept
returns a const reference to the last element; terminates if the vector is empty
- Attention
Accessing an empty vector can lead to a program termination!
- Returns:
const reference to the last element
-
uint64_t capacity() const noexcept
returns the capacity of the vector which was given via the template argument
-
uint64_t size() const noexcept
returns the number of elements which are currently stored in the vector
-
bool empty() const noexcept
returns true if the vector is emtpy, otherwise false
-
void clear() noexcept
calls the destructor of all contained elements and removes them
-
template<typename ...Targs>
bool resize(const uint64_t count, const Targs&... args) noexcept resizes the vector. If the vector size increases new elements will be constructed with the given arguments. If count is greater than the capacity the vector will stay unchanged.
Note
perfect forwarded arguments are explicitly not wanted here. think of what happens if resize creates two new elements via move construction. The first one has a valid source but the second gets an already moved parameter.
- Parameters:
count – [in] new size of the vector
args – [in] arguments which are used by the constructor of newly created elements
- Returns:
true if the resize was successful, false if count is greater than the capacity.
-
template<typename ...Targs>
bool emplace(const uint64_t position, Targs&&... args) noexcept forwards all arguments to the constructor of the contained element and performs a placement new at the provided position
- Parameters:
position – [in] the position where the element should be created
-
template<typename ...Targs>
bool emplace_back(Targs&&... args) noexcept forwards all arguments to the constructor of the contained element and performs a placement new at the end
-
bool push_back(const T &value) noexcept
appends the given element at the end of the vector
- Returns:
true if successful, false if vector already full
-
bool push_back(T &&value) noexcept
appends the given element at the end of the vector
- Returns:
true if successful, false if vector already full
-
bool pop_back() noexcept
removes the last element of the vector; calling pop_back on an empty container does nothing
- Returns:
true if the last element was removed. If the vector is empty it returns false.