]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdbsupport] Use std::span-style iterators for gdb::array_view
authorTom de Vries <tdevries@suse.de>
Sat, 19 Oct 2024 06:10:38 +0000 (08:10 +0200)
committerTom de Vries <tdevries@suse.de>
Sat, 19 Oct 2024 06:10:38 +0000 (08:10 +0200)
There's a plan to replace gdb::array_view with std::span (PR31422), and making
gdb::array_view more like std::span helps with that.

One difference is that std::span has:
...
constexpr iterator begin() const noexcept;
constexpr const_iterator cbegin() const noexcept;
...
while gdb::array_view has:
...
constexpr T *begin () noexcept;
constexpr const T *begin () const noexcept;
...

Fix this by renaming the second variant to cbegin, and making the first
variant const.

Likewise for gdb::array_view::end.

Tested on aarch64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
gdbsupport/array-view.h

index 93842a40ec1d02fb08e4aabfcc5250ac32961968..0dea26f67acd68ddcca3ec89f6fc137b392e0d59 100644 (file)
@@ -157,11 +157,11 @@ public:
   constexpr T *data () noexcept { return m_array; }
   constexpr const T *data () const noexcept { return m_array; }
 
-  constexpr T *begin () noexcept { return m_array; }
-  constexpr const T *begin () const noexcept { return m_array; }
+  constexpr T *begin () const noexcept { return m_array; }
+  constexpr const T *cbegin () const noexcept { return m_array; }
 
-  constexpr T *end () noexcept { return m_array + m_size; }
-  constexpr const T *end () const noexcept { return m_array + m_size; }
+  constexpr T *end () const noexcept { return m_array + m_size; }
+  constexpr const T *cend () const noexcept { return m_array + m_size; }
 
   constexpr reference operator[] (size_t index) noexcept
   {