iceoryx_hoofs 2.0.3
Public Types | Public Member Functions | List of all members
iox::cxx::vector< T, Capacity > Class Template Reference

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. More...

#include <iceoryx_hoofs/cxx/vector.hpp>

Public Types

using value_type = T
 
using iterator = T *
 
using const_iterator = const T *
 

Public Member 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 More...
 
 vector (const uint64_t count) noexcept
 creates a vector with count copies of elements constructed with the default constructor of T More...
 
 vector (const vector &rhs) noexcept
 copy constructor to copy a vector of the same capacity
 
 vector (vector &&rhs) noexcept
 move constructor to move a vector of the same capacity
 
 ~vector () noexcept
 destructs the vector and also calls the destructor of all contained elements
 
vectoroperator= (const vector &rhs) noexcept
 copy assignment. if the destination vector contains more elements than the source the remaining elements will be destructed
 
vectoroperator= (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)
 
T * data () noexcept
 return the pointer to the underlying array More...
 
const T * data () const noexcept
 return the const pointer to the underlying array More...
 
T & at (const uint64_t index) noexcept
 returns a reference to the element stored at index. the behavior More...
 
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. More...
 
T & operator[] (const uint64_t index) noexcept
 returns a reference to the element stored at index. the behavior More...
 
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. More...
 
T & front () noexcept
 returns a reference to the first element; terminates if the vector is empty More...
 
const T & front () const noexcept
 returns a const reference to the first element; terminates if the vector is empty More...
 
T & back () noexcept
 returns a reference to the last element; terminates if the vector is empty More...
 
const T & back () const noexcept
 returns a const reference to the last element; terminates if the vector is empty More...
 
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. More...
 
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 More...
 
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 More...
 
bool push_back (T &&value) noexcept
 appends the given element at the end of the vector More...
 
bool pop_back () noexcept
 removes the last element of the vector; calling pop_back on an empty container does nothing More...
 
iterator erase (iterator position) noexcept
 removes an element at the given position. if this element is in the middle of the vector every element is moved one place to the left to ensure that the elements are stored contiguously
 

Detailed Description

template<typename T, uint64_t Capacity>
class iox::cxx::vector< T, Capacity >

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!

Constructor & Destructor Documentation

◆ vector() [1/2]

template<typename T , uint64_t Capacity>
iox::cxx::vector< T, Capacity >::vector ( const uint64_t  count,
const T &  value 
)
noexcept

creates a vector with count copies of elements with value value

Parameters
[in]countis the number copies which are inserted into the vector
[in]valueis the value which is inserted into the vector

◆ vector() [2/2]

template<typename T , uint64_t Capacity>
iox::cxx::vector< T, Capacity >::vector ( const uint64_t  count)
noexcept

creates a vector with count copies of elements constructed with the default constructor of T

Parameters
[in]countis the number copies which are inserted into the vector

Member Function Documentation

◆ at() [1/2]

template<typename T , uint64_t Capacity>
const T & iox::cxx::vector< T, Capacity >::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!

◆ at() [2/2]

template<typename T , uint64_t Capacity>
T & iox::cxx::vector< T, Capacity >::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!

◆ back() [1/2]

template<typename T , uint64_t Capacity>
const T & iox::cxx::vector< T, Capacity >::back ( ) const
noexcept

returns a const reference to the last element; terminates if the vector is empty

Returns
const reference to the last element
Attention
Accessing an empty vector can lead to a program termination!

◆ back() [2/2]

template<typename T , uint64_t Capacity>
T & iox::cxx::vector< T, Capacity >::back ( )
noexcept

returns a reference to the last element; terminates if the vector is empty

Returns
reference to the last element
Attention
Accessing an empty vector can lead to a program termination!

◆ data() [1/2]

template<typename T , uint64_t Capacity>
const T * iox::cxx::vector< T, Capacity >::data ( ) const
noexcept

return the const pointer to the underlying array

Returns
const pointer to underlying array

◆ data() [2/2]

template<typename T , uint64_t Capacity>
T * iox::cxx::vector< T, Capacity >::data ( )
noexcept

return the pointer to the underlying array

Returns
pointer to underlying array

◆ emplace()

template<typename T , uint64_t Capacity>
template<typename... Targs>
bool iox::cxx::vector< T, Capacity >::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
[in]positionthe position where the element should be created

◆ front() [1/2]

template<typename T , uint64_t Capacity>
const T & iox::cxx::vector< T, Capacity >::front ( ) const
noexcept

returns a const reference to the first element; terminates if the vector is empty

Returns
const reference to the first element
Attention
Accessing an empty vector can lead to a program termination!

◆ front() [2/2]

template<typename T , uint64_t Capacity>
T & iox::cxx::vector< T, Capacity >::front ( )
noexcept

returns a reference to the first element; terminates if the vector is empty

Returns
reference to the first element
Attention
Accessing an empty vector can lead to a program termination!

◆ operator[]() [1/2]

template<typename T , uint64_t Capacity>
const T & iox::cxx::vector< T, Capacity >::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!

◆ operator[]() [2/2]

template<typename T , uint64_t Capacity>
T & iox::cxx::vector< T, Capacity >::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!

◆ pop_back()

template<typename T , uint64_t Capacity>
bool iox::cxx::vector< T, Capacity >::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.

◆ push_back() [1/2]

template<typename T , uint64_t Capacity>
bool iox::cxx::vector< T, Capacity >::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

◆ push_back() [2/2]

template<typename T , uint64_t Capacity>
bool iox::cxx::vector< T, Capacity >::push_back ( T &&  value)
noexcept

appends the given element at the end of the vector

Returns
true if successful, false if vector already full

◆ resize()

template<typename T , uint64_t Capacity>
template<typename... Targs>
bool iox::cxx::vector< T, Capacity >::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.

Parameters
[in]countnew size of the vector
[in]argsarguments 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.
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.

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