From 49f917776cce6822925b9dcdebdff8a154df2db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Tr=C3=A1vn=C3=AD=C4=8Dek?= <jan.travnicek@fit.cvut.cz> Date: Sun, 26 Dec 2021 06:48:59 +0100 Subject: [PATCH] std: stop using std::iterator std::iterator is deprecated in C++17 --- .../src/extensions/container/forward_tree.hpp | 26 +++++++++++++--- alib2std/src/extensions/container/tree.hpp | 31 ++++++++++++++++--- alib2std/src/extensions/iterator.hpp | 8 ++++- .../test-src/extensions/container/MapTest.cpp | 4 +-- 4 files changed, 58 insertions(+), 11 deletions(-) diff --git a/alib2std/src/extensions/container/forward_tree.hpp b/alib2std/src/extensions/container/forward_tree.hpp index 7eb236b1be..204f348799 100644 --- a/alib2std/src/extensions/container/forward_tree.hpp +++ b/alib2std/src/extensions/container/forward_tree.hpp @@ -115,7 +115,7 @@ public: * * The iterator performs a top to bottom, left to right or depth first travrsal stopping at each node twice. Once as it enters it the first time and second time when it leaves it (on the way to its parent). */ - class const_structure_iterator : public std::iterator < std::bidirectional_iterator_tag, T > { + class const_structure_iterator { /** * \brief * The underlying iterator within some list of children. @@ -141,6 +141,12 @@ public: bool isEnd; public: + using difference_type = std::ptrdiff_t; + using value_type = T; + using pointer = const T*; + using reference = const T&; + using iterator_category = std::bidirectional_iterator_tag; + /** * \brief * Constructor of the iterator based on the iterator to child list @@ -319,7 +325,7 @@ public: * * The prefix iterator is constructed as a wrapper over structure iterator, it selects only non-virtual nodes. */ - class const_prefix_iterator : public std::iterator < std::bidirectional_iterator_tag, T > { + class const_prefix_iterator { /** * \brief * The underlying structure iterator. @@ -327,6 +333,12 @@ public: const_structure_iterator node; public: + using difference_type = std::ptrdiff_t; + using value_type = T; + using pointer = const T*; + using reference = const T&; + using iterator_category = std::bidirectional_iterator_tag; + /** * \brief * Constructor of the iterator based on the iterator to child list @@ -450,7 +462,7 @@ public: * * The prefix iterator is constructed as a wrapper over structure iterator, it selects only virtual nodes. */ - class const_postfix_iterator : public std::iterator < std::bidirectional_iterator_tag, T > { + class const_postfix_iterator { /** * \brief * The underlying structure iterator. @@ -458,6 +470,12 @@ public: const_structure_iterator node; public: + using difference_type = std::ptrdiff_t; + using value_type = T; + using pointer = const T*; + using reference = const T&; + using iterator_category = std::bidirectional_iterator_tag; + /** * \brief * Constructor of the iterator based on the iterator to child list @@ -589,7 +607,7 @@ private: * * \return vector of unary nodes constructed from the begin and end range */ - template < std::input_iterator Iterator > + template < typename Iterator > ext::vector < forward_tree > fromIterator ( Iterator begin, Iterator end ) { ext::vector < forward_tree > res; diff --git a/alib2std/src/extensions/container/tree.hpp b/alib2std/src/extensions/container/tree.hpp index 37f8b2e752..c13a6520d8 100644 --- a/alib2std/src/extensions/container/tree.hpp +++ b/alib2std/src/extensions/container/tree.hpp @@ -28,6 +28,11 @@ #include <extensions/iterator.hpp> +#include <version> +#ifndef __cpp_lib_three_way_comparison +#include <extensions/compare.hpp> +#endif + namespace ext { /** @@ -139,7 +144,7 @@ public: * * The iterator performs a top to bottom, left to right or depth first travrsal stopping at each node twice. Once as it enters it the first time and second time when it leaves it (on the way to its parent). */ - class const_structure_iterator : public std::iterator < std::bidirectional_iterator_tag, T > { + class const_structure_iterator { /** * \brief * The underlying iterator within some list of children. @@ -165,6 +170,12 @@ public: bool isEnd; public: + using difference_type = std::ptrdiff_t; + using value_type = T; + using pointer = const T*; + using reference = const T&; + using iterator_category = std::bidirectional_iterator_tag; + /** * \brief * Constructor of the iterator based on the iterator to child list @@ -344,7 +355,7 @@ public: * * The prefix iterator is constructed as a wrapper over structure iterator, it selects only non-virtual nodes. */ - class const_prefix_iterator : public std::iterator < std::bidirectional_iterator_tag, T > { + class const_prefix_iterator { /** * \brief * The underlying structure iterator. @@ -352,6 +363,12 @@ public: const_structure_iterator node; public: + using difference_type = std::ptrdiff_t; + using value_type = T; + using pointer = const T*; + using reference = const T&; + using iterator_category = std::bidirectional_iterator_tag; + /** * \brief * Constructor of the iterator based on the iterator to child list @@ -475,7 +492,7 @@ public: * * The prefix iterator is constructed as a wrapper over structure iterator, it selects only virtual nodes. */ - class const_postfix_iterator : public std::iterator < std::bidirectional_iterator_tag, T > { + class const_postfix_iterator { /** * \brief * The underlying structure iterator. @@ -483,6 +500,12 @@ public: const_structure_iterator node; public: + using difference_type = std::ptrdiff_t; + using value_type = T; + using pointer = const T*; + using reference = const T&; + using iterator_category = std::bidirectional_iterator_tag; + /** * \brief * Constructor of the iterator based on the iterator to child list @@ -614,7 +637,7 @@ private: * * \return vector of unary nodes constructed from the begin and end range */ - template < std::input_iterator Iterator > + template < class Iterator > ext::vector < tree > fromIterator ( Iterator begin, Iterator end ) { ext::vector < tree > res; diff --git a/alib2std/src/extensions/iterator.hpp b/alib2std/src/extensions/iterator.hpp index 91b74c29cd..bcc0440811 100644 --- a/alib2std/src/extensions/iterator.hpp +++ b/alib2std/src/extensions/iterator.hpp @@ -915,13 +915,19 @@ auto end ( Container && cont ) -> decltype ( std::forward ( cont ).end ( ) ) { * \tparam the type of value accepted by the callback. The type must include the reference and cv-qualification if needed. */ template < class T > -class callback_iterator : public std::iterator < std::output_iterator_tag, void, void, void, void > { +class callback_iterator { /** * The callback. */ T m_callback; public: + using difference_type = void; + using value_type = void; + using pointer = void; + using reference = void; + using iterator_category = std::output_iterator_tag; + /** * Constructor of the callback iterator based on callback * diff --git a/alib2std/test-src/extensions/container/MapTest.cpp b/alib2std/test-src/extensions/container/MapTest.cpp index e2d3f5e65d..bf252b5586 100644 --- a/alib2std/test-src/extensions/container/MapTest.cpp +++ b/alib2std/test-src/extensions/container/MapTest.cpp @@ -70,8 +70,8 @@ TEST_CASE ( "Map", "[unit][std][container]" ) { ext::reference_mover < ext::map < ext::reference_wrapper < Moveable >, Moveable > > && __range1 = ext::make_mover ( map ); - ext::map_move_iterator < std::_Rb_tree_iterator < std::pair < const ext::reference_wrapper < Moveable >, Moveable > >, ext::reference_wrapper < Moveable >, Moveable > __begin1 = __range1.begin ( ); - ext::map_move_iterator < std::_Rb_tree_iterator < std::pair < const ext::reference_wrapper < Moveable >, Moveable > >, ext::reference_wrapper < Moveable >, Moveable > __end1 =__range1.end ( ); + auto __begin1 = __range1.begin ( ); + auto __end1 =__range1.end ( ); for(; __begin1 != __end1; __begin1.operator++()) { std::pair < ext::reference_wrapper < Moveable >, Moveable > && moveablePair = __begin1.operator*(); -- GitLab