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 <iceoryx_hoofs/cxx/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.

Attention: Out of bounds access or accessing an empty vector can lead to a program termination!

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🔗

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🔗

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🔗

vector(
    const vector & rhs
)

copy constructor to copy a vector of the same capacity

function vector🔗

vector(
    vector && rhs
)

move constructor to move a vector of the same capacity

function ~vector🔗

~vector()

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

function operator=🔗

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=🔗

vector & operator=(
    vector && rhs
)

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

function begin🔗

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🔗

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🔗

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🔗

T & at(
    const uint64_t index
)

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

Attention: Out of bounds access can lead to a program termination!

function at🔗

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.

Attention: Out of bounds access can lead to a program termination!

function operator[]🔗

T & operator[](
    const uint64_t index
)

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

Attention: Out of bounds access can lead to a program termination!

function operator[]🔗

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.

Attention: Out of bounds access can lead to a program termination!

function front🔗

T & front()

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

Return: reference to the first element

Attention: Accessing an empty vector can lead to a program termination!

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

Attention: Accessing an empty vector can lead to a program termination!

function back🔗

T & back()

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

Return: reference to the last element

Attention: Accessing an empty vector can lead to a program termination!

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

Attention: Accessing an empty vector can lead to a program termination!

function capacity🔗

uint64_t capacity() const

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

function size🔗

uint64_t size() const

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

function empty🔗

bool empty() const

returns true if the vector is emtpy, otherwise false

function clear🔗

void clear()

calls the destructor of all contained elements and removes them

function resize🔗

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.

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>
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>
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🔗

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🔗

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🔗

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🔗

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 2 April 2022 at 16:37:47 CEST