include/o3tl/enumarray.hxx |   71 ++++-----------------------------------------
 1 file changed, 7 insertions(+), 64 deletions(-)

New commits:
commit a0eb4dcd04a6d8f4a6df474f74edceb8936a3aa6
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue Aug 19 12:17:14 2025 +0200
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Tue Aug 19 15:08:20 2025 +0200

    Drop custom iterators for enumarray, use std::array's
    
    Which became an option since commit
      b9d360405a26ec976e443d501757ad806ffdcd6b
      o3tl: use std::array as the container for enumarray
      2022-07-27
    
    and magically makes the iterators random-access.
    
    Change-Id: I4842a8ee0b3276ddb0098282337ee283e5412b44
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189906
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/include/o3tl/enumarray.hxx b/include/o3tl/enumarray.hxx
index 0ea89c855f2b..e08274c2e48d 100644
--- a/include/o3tl/enumarray.hxx
+++ b/include/o3tl/enumarray.hxx
@@ -29,11 +29,6 @@
 
 namespace o3tl {
 
-template<typename EA>
-class enumarray_iterator;
-template<typename EA>
-class enumarray_const_iterator;
-
 ///
 /// This is a container convenience class for arrays indexed by enum values.
 ///
@@ -48,16 +43,15 @@ template<typename E, typename V>
 class enumarray final
 {
 public:
-    typedef enumarray<E, V> self_type;
-    typedef enumarray_iterator<self_type> iterator;
-    typedef enumarray_const_iterator<self_type> const_iterator;
-
     typedef V             value_type;
     typedef E             key_type;
     typedef size_t        size_type;
 
     static const size_type max_index = static_cast<size_type>(E::LAST);
 
+    typedef typename std::array<V, max_index + 1>::iterator iterator;
+    typedef typename std::array<V, max_index + 1>::const_iterator 
const_iterator;
+
     template <std::convertible_to<V>... T>
         requires(sizeof...(T) == max_index + 1)
     constexpr enumarray(T&&... args)
@@ -84,10 +78,10 @@ public:
     { for (size_type i=0; i<=max_index; ++i) detail_values[i] = val; }
 
     static size_type size()        { return max_index + 1; }
-    iterator         begin()       { return iterator(*this, 0); }
-    iterator         end()         { return iterator(*this, size()); }
-    const_iterator   begin() const { return const_iterator(*this, 0); }
-    const_iterator   end() const   { return const_iterator(*this, size()); }
+    iterator         begin()       { return detail_values.begin(); }
+    iterator         end()         { return detail_values.end(); }
+    const_iterator   begin() const { return detail_values.begin(); }
+    const_iterator   end() const   { return detail_values.end(); }
 
     V*               data()       { return detail_values.data(); }
 
@@ -95,57 +89,6 @@ private:
     std::array<V, max_index + 1> detail_values;
 };
 
-
-template<typename EA>
-class enumarray_iterator {
-    EA*         m_buf;
-    size_t      m_pos;
-public:
-    typedef enumarray_iterator<EA>  self_type;
-    typedef typename EA::value_type value_type;
-    typedef typename EA::key_type   key_type;
-    typedef std::bidirectional_iterator_tag iterator_category; //should be 
random access, but that would require define subtraction operators on the enums
-    typedef
-        typename std::make_signed<
-            typename std::underlying_type<typename EA::key_type>::type>::type
-        difference_type;
-    typedef typename EA::value_type*   pointer;
-    typedef typename EA::value_type&   reference;
-
-    enumarray_iterator(EA& b, size_t start_pos)
-         : m_buf(&b), m_pos(start_pos) {}
-    value_type& operator*()  const { return 
(*m_buf)[static_cast<key_type>(m_pos)]; }
-    value_type* operator->() const { return &(operator*()); }
-    self_type&  operator++() { ++m_pos; return *this; }
-    bool        operator!=(self_type const & other) const { return m_buf != 
other.m_buf || m_pos != other.m_pos; }
-    bool        operator==(self_type const & other) const { return m_buf == 
other.m_buf && m_pos == other.m_pos; }
-};
-
-template<typename EA>
-class enumarray_const_iterator {
-    EA const *  m_buf;
-    size_t      m_pos;
-public:
-    typedef enumarray_const_iterator<EA>    self_type;
-    typedef typename EA::value_type const   value_type;
-    typedef typename EA::key_type           key_type;
-    typedef std::bidirectional_iterator_tag iterator_category; //should be 
random access, but that would require define subtraction operators on the enums
-    typedef
-        typename std::make_signed<
-            typename std::underlying_type<typename EA::key_type>::type>::type
-                                            difference_type;
-    typedef typename EA::value_type const * pointer;
-    typedef typename EA::value_type const & reference;
-
-    enumarray_const_iterator(EA const & b, size_t start_pos)
-         : m_buf(&b), m_pos(start_pos) {}
-    value_type& operator*()  const { return 
(*m_buf)[static_cast<key_type>(m_pos)]; }
-    value_type* operator->() const { return &(operator*()); }
-    self_type&  operator++() { ++m_pos; return *this; }
-    bool        operator!=(self_type const & other) const { return m_buf != 
other.m_buf || m_pos != other.m_pos; }
-    bool        operator==(self_type const & other) const { return m_buf == 
other.m_buf && m_pos == other.m_pos; }
-};
-
 }; // namespace o3tl
 
 #endif /* INCLUDED_O3TL_ENUMARRAY_HXX */

Reply via email to