From eaef25da14fa22775091714516262e5a5d87439c Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <github@naumov.de> Date: Tue, 4 Apr 2023 23:42:50 +0200 Subject: [PATCH] [BL] Satisfy bidirectional_iterator requirements Make the PolymorphicRandomAccessContainerViewIterator bidirectional iterator. --- BaseLib/ContainerTools.h | 12 ++++++++++++ Tests/BaseLib/TestContainerTools.cpp | 1 + 2 files changed, 13 insertions(+) diff --git a/BaseLib/ContainerTools.h b/BaseLib/ContainerTools.h index 5746fc827d0..0efee8fe996 100644 --- a/BaseLib/ContainerTools.h +++ b/BaseLib/ContainerTools.h @@ -49,6 +49,18 @@ struct PolymorphicRandomAccessContainerViewIterator return copy; } + PolymorphicRandomAccessContainerViewIterator& operator--() noexcept + { + --n_; + return *this; + } + PolymorphicRandomAccessContainerViewIterator operator--(int) noexcept + { + auto copy{*this}; + operator--(); + return copy; + } + [[nodiscard]] Element& operator*() const { return (*view_)[n_]; } [[nodiscard]] bool operator==( diff --git a/Tests/BaseLib/TestContainerTools.cpp b/Tests/BaseLib/TestContainerTools.cpp index 30ff8e7fc05..0406d4c2bfa 100644 --- a/Tests/BaseLib/TestContainerTools.cpp +++ b/Tests/BaseLib/TestContainerTools.cpp @@ -83,6 +83,7 @@ TEST(BaseLib, ContainerToolsIteratorAndRangeConcepts) using IteratorType = decltype(view.begin()); static_assert(std::input_iterator<IteratorType>); static_assert(std::forward_iterator<IteratorType>); + static_assert(std::bidirectional_iterator<IteratorType>); } TEST(BaseLib, ContainerToolsNoUpCast) -- GitLab