martinus / robin-hood-hashing

Fast & memory efficient hashtable based on robin hood hashing for C++11/14/17/20
https://gitter.im/martinus/robin-hood-hashing
MIT License
1.5k stars 143 forks source link

postfix increment operator #68

Closed marciso closed 4 years ago

marciso commented 4 years ago

May I suggest the following patch:

diff a/robin_hood.h b/robin_hood.h
--- a/robin_hood.h
+++ b/robin_hood.h
@@ -1199,6 +1199,14 @@ private:
             return *this;
         }

+        Iter operator++(int) noexcept {
+            Iter aux = *this;
+            mInfo++;
+            mKeyVals++;
+            fastForward();
+            return aux;
+        }
+
         reference operator*() const {
             return **mKeyVals;
         }

To satisfy LegacyInputIterator requirement, where post- and pre-increment are possible.

bstaletic commented 4 years ago

This is also the reason why this library can't be used with the C++20 algorithms. The algorithms require that robin_hood::unordered_map<K,V>::iterator satisfies std::input_or_output_iterator, which requires std::weakly_incrementable. std::weakly_incrementable directly checks that it can do it++.

martinus commented 4 years ago

Thanks, added in master.