Skip to content

iox::cxx::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. More...

#include <vector.hpp>

Public Types🔗

Name
using T value_type
using T * iterator
using const T * const_iterator

Public Functions🔗

Name
vector() =default
creates an empty vector
vector(const uint64_t count, const T & value)
creates a vector with count copies of elements with value value
vector(const uint64_t count)
creates a vector with count copies of elements constructed with the default constructor of T
vector(const vector & rhs)
copy constructor to copy a vector of the same capacity
vector(vector && rhs)
move constructor to move a vector of the same capacity
~vector()
destructs the vector and also calls the destructor of all contained elements
vector & operator=(const vector & rhs)
copy assignment. if the destination vector contains more elements than the source the remaining elements will be destructed
vector & operator=(vector && rhs)
move assignment. if the destination vector contains more elements than the source the remaining elements will be destructed
iterator begin()
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
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()
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
returns a const iterator to the element which comes after the last element (the first element which is outside of the vector)
T * data()
return the pointer to the underlying array
const T * data() const
return the const pointer to the underlying array
T & at(const uint64_t index)
returns a reference to the element stored at index. the behavior
const T & at(const uint64_t index) const
returns a const reference to the element stored at index. the behavior is undefined if the element at index does not exist.
T & operator[](const uint64_t index)
returns a reference to the element stored at index. the behavior
const T & operator[](const uint64_t index) const
returns a const reference to the element stored at index. the behavior is undefined if the element at index does not exist.
T & front()
returns a reference to the first element; terminates if the vector is empty
const T & front() const
returns a const reference to the first element; terminates if the vector is empty
T & back()
returns a reference to the last element; terminates if the vector is empty
const T & back() const
returns a const reference to the last element; terminates if the vector is empty
uint64_t capacity() const
returns the capacity of the vector which was given via the template argument
uint64_t size() const
returns the number of elements which are currently stored in the vector
bool empty() const
returns true if the vector is emtpy, otherwise false
void clear()
calls the destructor of all contained elements and removes them
template \<typename... Targs>
bool
resize(const uint64_t count, const Targs &... args)
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.
template \<typename... Targs>
bool
emplace(const uint64_t position, Targs &&... args)
forwards all arguments to the constructor of the contained element and performs a placement new at the provided position
template \<typename... Targs>
bool
emplace_back(Targs &&... args)
forwards all arguments to the constructor of the contained element and performs a placement new at the end
bool push_back(const T & value)
appends the given element at the end of the vector
bool push_back(T && value)
appends the given element at the end of the vector
bool pop_back()
removes the last element of the vector; calling pop_back on an empty container does nothing
iterator erase(iterator position)
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;

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.

Public Types Documentation🔗

using value_type🔗

using iox::cxx::vector< T, Capacity >::value_type =  T;

using iterator🔗

using iox::cxx::vector< T, Capacity >::iterator =  T*;

using const_iterator🔗

using iox::cxx::vector< T, Capacity >::const_iterator =  const T*;

Public Functions Documentation🔗

function vector🔗

vector() =default

creates an empty vector

function vector🔗

inline vector(
    const uint64_t count,
    const T & value
)

creates a vector with count copies of elements with value value

Parameters:

  • count is the number copies which are inserted into the vector
  • value is the value which is inserted into the vector

function vector🔗

inline vector(
    const uint64_t count
)

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

Parameters:

  • count is the number copies which are inserted into the vector

function vector🔗

inline vector(
    const vector & rhs
)

copy constructor to copy a vector of the same capacity

function vector🔗

inline vector(
    vector && rhs
)

move constructor to move a vector of the same capacity

function ~vector🔗

inline ~vector()

destructs the vector and also calls the destructor of all contained elements

function operator=🔗

inline vector & operator=(
    const vector & rhs
)

copy assignment. if the destination vector contains more elements than the source the remaining elements will be destructed

function operator=🔗

inline vector & operator=(
    vector && rhs
)

move assignment. if the destination vector contains more elements than the source the remaining elements will be destructed

function begin🔗

inline iterator begin()

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)

function begin🔗

const_iterator begin() const

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)

function end🔗

inline iterator end()

returns an iterator to the element which comes after the last element (the first element which is outside of the vector)

function end🔗

const_iterator end() const

returns a const iterator to the element which comes after the last element (the first element which is outside of the vector)

function data🔗

inline T * data()

return the pointer to the underlying array

Return: pointer to underlying array

function data🔗

const T * data() const

return the const pointer to the underlying array

Return: const pointer to underlying array

function at🔗

inline T & at(
    const uint64_t index
)

returns a reference to the element stored at index. the behavior

function at🔗

inline const T & at(
    const uint64_t index
) const

returns a const reference to the element stored at index. the behavior is undefined if the element at index does not exist.

function operator[]🔗

inline T & operator[](
    const uint64_t index
)

returns a reference to the element stored at index. the behavior

function operator[]🔗

inline const T & operator[](
    const uint64_t index
) const

returns a const reference to the element stored at index. the behavior is undefined if the element at index does not exist.

function front🔗

inline T & front()

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

Return: reference to the first element

function front🔗

const T & front() const

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

Return: const reference to the first element

function back🔗

inline T & back()

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

Return: reference to the last element

function back🔗

const T & back() const

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

Return: const reference to the last element

function capacity🔗

inline uint64_t capacity() const

returns the capacity of the vector which was given via the template argument

function size🔗

inline uint64_t size() const

returns the number of elements which are currently stored in the vector

function empty🔗

inline bool empty() const

returns true if the vector is emtpy, otherwise false

function clear🔗

inline void clear()

calls the destructor of all contained elements and removes them

function resize🔗

template <typename... Targs>
inline bool resize(
    const uint64_t count,
    const Targs &... args
)

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:

  • count new size of the vector
  • args arguments which are used by the constructor of newly created elements

Return: 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.

function emplace🔗

template <typename... Targs>
inline bool emplace(
    const uint64_t position,
    Targs &&... args
)

forwards all arguments to the constructor of the contained element and performs a placement new at the provided position

Parameters:

  • position the position where the element should be created

function emplace_back🔗

template <typename... Targs>
inline bool emplace_back(
    Targs &&... args
)

forwards all arguments to the constructor of the contained element and performs a placement new at the end

function push_back🔗

inline bool push_back(
    const T & value
)

appends the given element at the end of the vector

Return: true if successful, false if vector already full

function push_back🔗

inline bool push_back(
    T && value
)

appends the given element at the end of the vector

Return: true if successful, false if vector already full

function pop_back🔗

inline bool pop_back()

removes the last element of the vector; calling pop_back on an empty container does nothing

Return: true if the last element was removed. If the vector is empty it returns false.

function erase🔗

inline iterator erase(
    iterator position
)

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


Updated on 26 April 2021 at 15:31:01 CEST