From 8f1fa0d1307d7a60844de0ca33628e0c6997468e Mon Sep 17 00:00:00 2001 From: Jon Bailey Date: Mon, 12 May 2025 21:19:48 +0100 Subject: [PATCH] common: Add iterator traits to mini_flat_map and bitset_set iterator 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 --- src/common/bitset_set.h | 4 ++++ src/common/mini_flat_map.h | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/common/bitset_set.h b/src/common/bitset_set.h index d6d02144959..182d635b559 100644 --- a/src/common/bitset_set.h +++ b/src/common/bitset_set.h @@ -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) { } diff --git a/src/common/mini_flat_map.h b/src/common/mini_flat_map.h index 46abda51387..6d1cea34c15 100644 --- a/src/common/mini_flat_map.h +++ b/src/common/mini_flat_map.h @@ -50,14 +50,22 @@ class mini_flat_map { template class _iterator { friend class mini_flat_map; - using mini_flat_map_p = std::conditional_t; + + public: + // types required by std::iterator_traits using value_type = std::conditional_t, std::pair>; - + 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; mini_flat_map_p map; std::optional 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(); } -- 2.47.3