Skip to content

Commit

Permalink
[eclipse-iceoryx#490] Add size() method to iox::Slice
Browse files Browse the repository at this point in the history
  • Loading branch information
orecham committed Nov 2, 2024
1 parent 24ab1fe commit 18826ac
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions iceoryx2-ffi/cxx/include/iox/slice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class Slice {

Slice(const T* data, uint64_t number_of_elements);

auto size() const -> uint64_t;
auto number_of_elements() const -> uint64_t;

auto operator[](uint64_t n) const -> const T&;
auto operator[](uint64_t n) -> T&;

Expand All @@ -52,6 +54,11 @@ Slice<T>::Slice(const T* data, uint64_t number_of_elements)
, m_number_of_elements { number_of_elements } {
}

template <typename T>
auto Slice<T>::size() const -> uint64_t {
return (sizeof(ValueType) * m_number_of_elements + alignof(ValueType) - 1) & ~(alignof(ValueType) - 1);
}

template <typename T>
auto Slice<T>::number_of_elements() const -> uint64_t {
return m_number_of_elements;
Expand Down

0 comments on commit 18826ac

Please sign in to comment.