From 66a1f6f8ab76fde1d03c63dca043fca87b0174db Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 10 Jun 2024 19:24:58 +0200 Subject: [PATCH] Library: add iteration capability to the Several-container ...and the nice thing is, the recently built `IterIndex` iteration wrapper covers this functionality right away, simply because `lib::Several` is a generic container with subscript operator. --- src/lib/iter-index.hpp | 2 +- src/lib/several.hpp | 22 ++++++--- tests/library/iter-index-test.cpp | 20 +++++--- wiki/thinkPad.ichthyo.mm | 81 ++++++++++++++++++++++--------- 4 files changed, 87 insertions(+), 38 deletions(-) diff --git a/src/lib/iter-index.hpp b/src/lib/iter-index.hpp index 6e496e84a..59fb36809 100644 --- a/src/lib/iter-index.hpp +++ b/src/lib/iter-index.hpp @@ -29,7 +29,7 @@ ** as »Lumiera Forward Iterator«, the current access position can be retrieved directly ** and it can be relocated to another valid index position; this implies also the ability ** to re-set the iteration to the container's start. Optionally, a smart-ptr can be - ** embedded, allowing the handle also to owns and manage the data container. + ** embedded, allowing the handle also to own and manage the data container. ** ** @see IterIndex_test ** @see iter-adapter.hpp diff --git a/src/lib/several.hpp b/src/lib/several.hpp index da57eed7e..99f5b048d 100644 --- a/src/lib/several.hpp +++ b/src/lib/several.hpp @@ -63,7 +63,7 @@ #include "lib/nocopy.hpp" -#include "lib/iter-adapter.hpp" +#include "lib/iter-index.hpp" #include #include @@ -180,17 +180,25 @@ namespace lib { return data_->subscript (idx); } + I const& + operator[] (size_t idx) const + { + return const_cast(*this).operator[] (idx); + } + I& front() { return operator[] (0); } I& back() { return operator[] (data_? data_->cnt-1 : 0); } - using iterator = I*; - using const_iterator = I const*; + using iterator = lib::IterIndex; + using const_iterator = lib::IterIndex; - iterator begin() { UNIMPLEMENTED ("iteration"); } - iterator end() { UNIMPLEMENTED ("iteration"); } - const_iterator begin() const { UNIMPLEMENTED ("iteration"); } - const_iterator end() const { UNIMPLEMENTED ("iteration"); } + iterator begin() { return iterator{*this}; } + iterator end() { return iterator{}; } + const_iterator begin() const { return const_iterator{*this};} + const_iterator end() const { return const_iterator{}; } + friend auto begin (Several& svl) { return svl.begin();} + friend auto end (Several& svl) { return svl.end(); } friend auto begin (Several const& svl) { return svl.begin();} friend auto end (Several const& svl) { return svl.end(); } diff --git a/tests/library/iter-index-test.cpp b/tests/library/iter-index-test.cpp index 8122a876e..42b18e10b 100644 --- a/tests/library/iter-index-test.cpp +++ b/tests/library/iter-index-test.cpp @@ -127,12 +127,11 @@ namespace test{ - /** @test verify the ability of IterCursor to switch - * the direction of the iteration. This "gear switch" can be done - * any time, while in the middle of iteration, and even after - * iteration end. That means, even an exhausted iterator can be - * "turned back". This does not work on a default constructed - * IterCursor, though. + /** @test verify the ability of IterIndex to access and manipulate + * the current index position, which can be done any time, while in + * the middle of iteration, and even after iteration end. That means, + * even an exhausted iterator can be „reanimated“. This manipulation + * is not allowed on a default constructed IterIndex, though. */ void verify_randomAccess () @@ -173,12 +172,17 @@ namespace test{ CHECK (9 == iter.getIDX()); VERIFY_ERROR (INDEX_BOUNDS, iter.setIDX(-1)); CHECK (9 == iter.getIDX()); + + Iter empty; + CHECK (isnil (empty)); + VERIFY_ERROR (INDEX_BOUNDS, empty.setIDX(0)); + VERIFY_ERROR (ITER_EXHAUST, empty.getIDX()); } - /** @test verify the const and dereferencing variants, - * based on the const-ness of the underlying STL iterator + /** @test verify possible variations of this iterator template, + * using a const container or maintaining shared ownership. */ void iterTypeVariations () diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 393cf8fc3..2d4141bbe 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -1,6 +1,6 @@ - + @@ -81854,9 +81854,37 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - - + + + + + + + + + + +

+ ein einfacher Pointer geht nicht, wegen dem anzuwendenden Spread +

+ + +
+
+ + + + + + + + + + + + +
+ @@ -81918,7 +81946,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + @@ -81963,11 +81991,11 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + - + @@ -82018,17 +82046,25 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + - - - + + + + + + + - - - - + + + + + + + + @@ -82418,17 +82454,18 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - - - + + + + + - - + + - +