diff options
author | Tom de Vries <tdevries@suse.de> | 2024-10-19 08:10:38 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2024-10-19 08:10:38 +0200 |
commit | e686338105177046975bcff8fe6199536e80caf9 (patch) | |
tree | d45b762e839f333832bcc6916b3139ba63af3cfd /gdbsupport | |
parent | 6c8052f6b22fbb6ae1edc759454626d465ee317c (diff) | |
download | binutils-e686338105177046975bcff8fe6199536e80caf9.zip binutils-e686338105177046975bcff8fe6199536e80caf9.tar.gz binutils-e686338105177046975bcff8fe6199536e80caf9.tar.bz2 |
[gdbsupport] Add gdb::array_view::{iterator,const_iterator}
While trying to substitute some std::vector type A in the code with a
gdb::array_view:
...
- using A = std::vector<T>
+ using A = gdb::array_view<T>
....
I ran into the problem that the code was using A::iterator while
gdb::array_view doesn't define such a type.
Fix this by:
- adding types gdb::array_view::iterator and gdb::array_view::const_iterator,
- using them in gdb::array_view::(c)begin and gdb::array_view::(c)end, as is
usual, and
- using them explicitly in a unit test.
Tested on aarch64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdbsupport')
-rw-r--r-- | gdbsupport/array-view.h | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/gdbsupport/array-view.h b/gdbsupport/array-view.h index 0dea26f..5bf9ed7 100644 --- a/gdbsupport/array-view.h +++ b/gdbsupport/array-view.h @@ -88,6 +88,8 @@ public: using reference = T &; using const_reference = const T &; using size_type = size_t; + using const_iterator = const T *; + using iterator = T *; /* Default construction creates an empty view. */ constexpr array_view () noexcept @@ -157,11 +159,11 @@ public: constexpr T *data () noexcept { return m_array; } constexpr const T *data () const noexcept { return m_array; } - constexpr T *begin () const noexcept { return m_array; } - constexpr const T *cbegin () const noexcept { return m_array; } + constexpr iterator begin () const noexcept { return m_array; } + constexpr const_iterator cbegin () const noexcept { return m_array; } - constexpr T *end () const noexcept { return m_array + m_size; } - constexpr const T *cend () const noexcept { return m_array + m_size; } + constexpr iterator end () const noexcept { return m_array + m_size; } + constexpr const_iterator cend () const noexcept { return m_array + m_size; } constexpr reference operator[] (size_t index) noexcept { |