diff options
author | 2023-09-01 02:07:15 -0700 | |
---|---|---|
committer | 2023-09-08 23:54:07 +0000 | |
commit | 743ce223c81f33f2955c64f39f85ca6c64099cb7 (patch) | |
tree | 599a9888434fcf757fd64af72187adb5bf6efbbb /libartbase/base/bit_table.h | |
parent | 5899d7919d5ad8e0c437e72c4aa04d4024e32431 (diff) |
Stop inheriting from std::iterator
std::iterator was deprecated in C++17 and after upgrading libc++, the
compiler warns about the many uses of it in ART.
p0174r1 gives a couple of reasons for its deprecation:
"The long sequence of void arguments is much less clear to the reader
than simply providing the expected typedefs in the class definition
itself, which is the approach taken by the current working draft, ...
"In addition to the reduced clarity, the iterator template also lays a
trap for the unwary, as in typical usage it will be a dependent base
class, which means it will not be looking into during name lookup from
within the class or its member functions."
The first reason is illustrated by the comments in
BitTable::const_iterator. The second reason is illustrated by the
various "using foo = typename std::iterator<...>::foo" declarations.
Follow p0174r1's advice and simply provide the 5 typedefs in each
iterator class.
Bug: b/175635923
Test: treehugger
Change-Id: I2fba5af68eb05fd0a8ba5e2add0c8b8ed1ebee1a
Diffstat (limited to 'libartbase/base/bit_table.h')
-rw-r--r-- | libartbase/base/bit_table.h | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/libartbase/base/bit_table.h b/libartbase/base/bit_table.h index 227f5eb082..eb97b54e9d 100644 --- a/libartbase/base/bit_table.h +++ b/libartbase/base/bit_table.h @@ -153,13 +153,13 @@ static const char* const* GetBitTableColumnNamesImpl(std::index_sequence<Columns template<typename Accessor> class BitTable : public BitTableBase<Accessor::kNumColumns> { public: - class const_iterator : public std::iterator<std::random_access_iterator_tag, - /* value_type */ Accessor, - /* difference_type */ int32_t, - /* pointer */ void, - /* reference */ void> { + class const_iterator { public: + using iterator_category = std::random_access_iterator_tag; + using value_type = Accessor; using difference_type = int32_t; + using pointer = void; + using reference = void; const_iterator() {} const_iterator(const BitTable* table, uint32_t row) : table_(table), row_(row) {} const_iterator operator+(difference_type n) { return const_iterator(table_, row_ + n); } @@ -189,6 +189,7 @@ class BitTable : public BitTableBase<Accessor::kNumColumns> { DCHECK_LT(row_ + index, table_->NumRows()); return Accessor(table_, row_ + index); } + private: const BitTable* table_ = nullptr; uint32_t row_ = 0; |