Skip to content

Commit

Permalink
[core] linux warning fixed: use of std::iterator is deprecated (#1928)
Browse files Browse the repository at this point in the history
  • Loading branch information
rex-schilasky authored Jan 22, 2025
1 parent 34163c1 commit 91039b3
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions ecal/core/src/registration/shm/relocatable_circular_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,23 @@
#include <stdexcept>

template<class T>
class RelocatableCircularQueue{
class RelocatableCircularQueue {
public:
static constexpr auto invalid_index = std::numeric_limits<std::uint64_t>::max();

class iterator : public std::iterator<std::forward_iterator_tag, T, std::uint64_t> {
class iterator {
public:
explicit iterator(RelocatableCircularQueue<T>& relocatable_circular_queue, std::uint64_t index): m_relocatable_circular_queue(relocatable_circular_queue), m_index(index){
using iterator_category = std::forward_iterator_tag;
using value_type = T;
using difference_type = std::ptrdiff_t;
using pointer = T*;
using reference = T&;

explicit iterator(RelocatableCircularQueue<T>& relocatable_circular_queue, std::uint64_t index)
: m_relocatable_circular_queue(relocatable_circular_queue), m_index(index) {
}

iterator& operator++()
iterator& operator++()
{
if (m_index == m_relocatable_circular_queue.m_header->front_index)
m_index = invalid_index;
Expand Down Expand Up @@ -85,7 +92,7 @@ class RelocatableCircularQueue{

iterator begin()
{
if(m_header->size == 0)
if (m_header->size == 0)
return iterator(*this, invalid_index);
else
return iterator(*this, m_header->back_index);
Expand All @@ -98,7 +105,7 @@ class RelocatableCircularQueue{

const iterator begin() const
{
if(m_header->size == 0)
if (m_header->size == 0)
return iterator(*this, invalid_index);
else
return iterator(*this, m_header->back_index);
Expand All @@ -109,7 +116,7 @@ class RelocatableCircularQueue{
return iterator(*this, invalid_index);
}

RelocatableCircularQueue(): m_header(nullptr)
RelocatableCircularQueue() : m_header(nullptr)
{}

void Push(const T& value)
Expand Down Expand Up @@ -218,18 +225,18 @@ class RelocatableCircularQueue{
};
#pragma pack(pop)

void* m_base_address{nullptr};
void* m_base_address{ nullptr };
Header* m_header;

T * Value(std::uint64_t index)
T* Value(std::uint64_t index)
{
assert(m_base_address != nullptr);
return reinterpret_cast<T *>(static_cast<char *>(m_base_address) + sizeof(Header) + sizeof(T) * index);
return reinterpret_cast<T*>(static_cast<char*>(m_base_address) + sizeof(Header) + sizeof(T) * index);
}

const T * Value(std::uint64_t index) const
const T* Value(std::uint64_t index) const
{
assert(m_base_address != nullptr);
return reinterpret_cast<const T *>(static_cast<char *>(m_base_address) + sizeof(Header) + sizeof(T) * index);
return reinterpret_cast<const T*>(static_cast<char*>(m_base_address) + sizeof(Header) + sizeof(T) * index);
}
};

0 comments on commit 91039b3

Please sign in to comment.