From dd4230d74363891fa3b0ede9ca52213e0b773873 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 4 May 2018 20:19:55 -0700 Subject: [PATCH] StringMap: Add decrement operations to iterator. --- wpiutil/src/main/native/include/wpi/StringMap.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/wpiutil/src/main/native/include/wpi/StringMap.h b/wpiutil/src/main/native/include/wpi/StringMap.h index a6b9375163..55e646518e 100644 --- a/wpiutil/src/main/native/include/wpi/StringMap.h +++ b/wpiutil/src/main/native/include/wpi/StringMap.h @@ -450,11 +450,24 @@ public: StringMapConstIterator tmp = *this; ++*this; return tmp; } + inline StringMapConstIterator& operator--() { // Predecrement + --Ptr; + ReversePastEmptyBuckets(); + return *this; + } + StringMapConstIterator operator--(int) { // Postdecrement + StringMapConstIterator tmp = *this; --*this; return tmp; + } + private: void AdvancePastEmptyBuckets() { while (*Ptr == nullptr || *Ptr == StringMapImpl::getTombstoneVal()) ++Ptr; } + void ReversePastEmptyBuckets() { + while (*Ptr == nullptr || *Ptr == StringMapImpl::getTombstoneVal()) + --Ptr; + } }; template