Skip to content

Commit

Permalink
iox-eclipse-iceoryx#261 Avoid code duplication in vector front() and …
Browse files Browse the repository at this point in the history
…back()

Signed-off-by: Simon Hoinkis <simon.hoinkis@apex.ai>
  • Loading branch information
mossmaurice committed Apr 22, 2021
1 parent d3934c4 commit c220deb
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions iceoryx_utils/include/iceoryx_utils/internal/cxx/vector.inl
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,7 @@ inline T& vector<T, Capacity>::front() noexcept
template <typename T, uint64_t Capacity>
inline const T& vector<T, Capacity>::front() const noexcept
{
// No empty vector shall be accessed
cxx::Expects(!empty() && "Attempting to access the front of an empty vector");
return at(0);
return const_cast<vector<T, Capacity>*>(this)->front();
}

template <typename T, uint64_t Capacity>
Expand All @@ -312,9 +310,7 @@ inline T& vector<T, Capacity>::back() noexcept
template <typename T, uint64_t Capacity>
inline const T& vector<T, Capacity>::back() const noexcept
{
// No empty vector shall be accessed
cxx::Expects(!empty() && "Attempting to access the back of an empty vector");
return at(size() - 1);
return const_cast<vector<T, Capacity>*>(this)->back();
}

template <typename T, uint64_t Capacity>
Expand Down

0 comments on commit c220deb

Please sign in to comment.