]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: Add iterator traits to mini_flat_map and bitset_set iterator
authorJon Bailey <jonathan.bailey1@ibm.com>
Mon, 12 May 2025 20:19:48 +0000 (21:19 +0100)
committerJon Bailey <jonathan.bailey1@ibm.com>
Mon, 14 Jul 2025 14:16:52 +0000 (15:16 +0100)
Add iterator traits to mini_flat_map and bitset_set iterator to allow std algorithms to be able to perform operations using the mini_flat_map iterator

Signed-off-by: Jon Bailey <jonathan.bailey1@ibm.com>
src/common/bitset_set.h
src/common/mini_flat_map.h

index d6d021449598383669f46c0ae4e476890017c839..182d635b55996230d5abdafc219d0a05f9fd6d81 100644 (file)
@@ -39,7 +39,11 @@ class bitset_set {
     KeyT pos;
 
    public:
+    using value_type = const KeyT;
     using difference_type = std::int64_t;
+    using pointer = const value_type *;
+    using reference = const value_type &;
+    using iterator_category = std::forward_iterator_tag;
 
     const_iterator() : set(nullptr), pos(0) {
     }
index 46abda5138729992897b6f634bad1d604de6623a..6d1cea34c15d77d10d50fe57e2caf8138906cf46 100644 (file)
@@ -50,14 +50,22 @@ class mini_flat_map {
   template<bool is_const>
   class _iterator {
     friend class mini_flat_map;
-    using mini_flat_map_p = std::conditional_t<is_const,
-                                               const mini_flat_map *,
-                                               mini_flat_map *>;
+
+   public:
+    // types required by std::iterator_traits
     using value_type = std::conditional_t<is_const,
                                           const std::pair<const KeyT &,
                                                           const ValueT &>,
                                           std::pair<const KeyT &, ValueT &>>;
-
+    using difference_type = std::ptrdiff_t;
+    using pointer = const value_type *;
+    using reference = const value_type &;
+    using iterator_category = std::forward_iterator_tag;
+
+   private:
+   using mini_flat_map_p = std::conditional_t<is_const,
+                                              const mini_flat_map *,
+                                              mini_flat_map *>;
     mini_flat_map_p map;
     std::optional<value_type> value;
     KeyT key;
@@ -73,8 +81,6 @@ class mini_flat_map {
     }
 
    public:
-    using difference_type = std::ptrdiff_t;
-
     _iterator(mini_flat_map_p map) : map(map), key(0) {
       progress();
     }