From e665aeb33326a1fe4e11b4b29099960a4e32d6b7 Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:08:14 +0100 Subject: [PATCH 1/2] ecal_expmap not using std::iterator anymore --- ecal/core/src/util/ecal_expmap.h | 58 ++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/ecal/core/src/util/ecal_expmap.h b/ecal/core/src/util/ecal_expmap.h index ba3959e1b7..229a0f588d 100644 --- a/ecal/core/src/util/ecal_expmap.h +++ b/ecal/core/src/util/ecal_expmap.h @@ -5,9 +5,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,13 +23,14 @@ #pragma once +#include #include +#include #include #include #include #include #include -#include namespace eCAL { @@ -41,32 +42,35 @@ namespace eCAL template, - class Alloc = std::allocator > > - class CExpMap + class Alloc = std::allocator > > + class CExpMap { public: using clock_type = std::chrono::steady_clock; // Key access history, most recent at back using key_tracker_type = std::list>; + // Key to value and key history iterator using key_to_value_type = std::map>; - using allocator_type = Alloc; - using value_type = std::pair; - using reference = typename Alloc::reference; - using const_reference = typename Alloc::const_reference; - using difference_type = typename Alloc::difference_type; - using size_type = typename Alloc::size_type; - using key_type = Key; - using mapped_type = T; + using allocator_type = Alloc; + using value_type = std::pair; + using reference = typename Alloc::reference; + using size_type = typename Alloc::size_type; + using key_type = Key; + using mapped_type = T; - class iterator : public std::iterator> + class iterator { friend class const_iterator; public: - iterator(const typename key_to_value_type::iterator _it) + using value_type = std::pair; + using pointer = std::pair*; + using reference = std::pair&; + + explicit iterator(const typename key_to_value_type::iterator _it) : it(_it) {} @@ -86,44 +90,48 @@ namespace eCAL { return std::make_pair(it->first, it->second.first); } - + //friend void swap(iterator& lhs, iterator& rhs); //C++11 I think bool operator==(const iterator& rhs) const { return it == rhs.it; } bool operator!=(const iterator& rhs) const { return it != rhs.it; } private: typename key_to_value_type::iterator it; - }; + }; - class const_iterator : public std::iterator> + class const_iterator { public: - const_iterator(const iterator& other) + using value_type = std::pair; + using pointer = std::pair*; + using reference = std::pair&; + + explicit const_iterator(const iterator& other) : it(other.it) {} - const_iterator(const typename key_to_value_type::const_iterator _it) + explicit const_iterator(const typename key_to_value_type::const_iterator _it) : it(_it) {} - + const_iterator& operator++() { it++; return *this; } //prefix increment - + const_iterator& operator--() { it--; return *this; } //prefix decrement //reference operator*() const - + std::pair operator*() const { return std::make_pair(it->first, it->second.first); } - + //friend void swap(iterator& lhs, iterator& rhs); //C++11 I think bool operator==(const const_iterator& rhs) const { return it == rhs.it; } bool operator!=(const const_iterator& rhs) const { return it != rhs.it; } @@ -135,7 +143,7 @@ namespace eCAL // Constructor specifies the timeout of the map CExpMap() : _timeout(std::chrono::milliseconds(5000)) {}; - CExpMap(clock_type::duration t) : _timeout(t) {}; + explicit CExpMap(clock_type::duration t) : _timeout(t) {}; /** * @brief set expiration time From 0bec7ab773f81db37f634aaa181993c91c52d710 Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Mon, 12 Feb 2024 12:45:17 +0100 Subject: [PATCH 2/2] added missing iterator fields --- ecal/core/src/util/ecal_expmap.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ecal/core/src/util/ecal_expmap.h b/ecal/core/src/util/ecal_expmap.h index 229a0f588d..b9a321b2da 100644 --- a/ecal/core/src/util/ecal_expmap.h +++ b/ecal/core/src/util/ecal_expmap.h @@ -66,9 +66,11 @@ namespace eCAL friend class const_iterator; public: - using value_type = std::pair; - using pointer = std::pair*; - using reference = std::pair&; + using iterator_category = std::bidirectional_iterator_tag; + using value_type = std::pair; + using difference_type = std::ptrdiff_t; + using pointer = std::pair*; + using reference = std::pair&; explicit iterator(const typename key_to_value_type::iterator _it) : it(_it) @@ -102,9 +104,11 @@ namespace eCAL class const_iterator { public: - using value_type = std::pair; - using pointer = std::pair*; - using reference = std::pair&; + using iterator_category = std::bidirectional_iterator_tag; + using value_type = std::pair; + using difference_type = std::ptrdiff_t; + using pointer = std::pair*; + using reference = std::pair&; explicit const_iterator(const iterator& other) : it(other.it)