summaryrefslogtreecommitdiff
path: root/libartbase/base/stl_util.h
diff options
context:
space:
mode:
author Ryan Prichard <rprichard@google.com> 2023-09-01 02:07:15 -0700
committer Ryan Prichard <rprichard@google.com> 2023-09-08 23:54:07 +0000
commit743ce223c81f33f2955c64f39f85ca6c64099cb7 (patch)
tree599a9888434fcf757fd64af72187adb5bf6efbbb /libartbase/base/stl_util.h
parent5899d7919d5ad8e0c437e72c4aa04d4024e32431 (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/stl_util.h')
-rw-r--r--libartbase/base/stl_util.h35
1 files changed, 28 insertions, 7 deletions
diff --git a/libartbase/base/stl_util.h b/libartbase/base/stl_util.h
index 2c9547f020..cb3e4cb43e 100644
--- a/libartbase/base/stl_util.h
+++ b/libartbase/base/stl_util.h
@@ -156,10 +156,14 @@ static inline std::vector<T*> MakeNonOwningPointerVector(const std::vector<std::
}
template <typename IterLeft, typename IterRight>
-class ZipLeftIter : public std::iterator<
- std::forward_iterator_tag,
- std::pair<typename IterLeft::value_type, typename IterRight::value_type>> {
+class ZipLeftIter {
public:
+ using iterator_category = std::forward_iterator_tag;
+ using value_type = std::pair<typename IterLeft::value_type, typename IterRight::value_type>;
+ using difference_type = ptrdiff_t;
+ using pointer = value_type*;
+ using reference = value_type&;
+
ZipLeftIter(IterLeft left, IterRight right) : left_iter_(left), right_iter_(right) {}
ZipLeftIter<IterLeft, IterRight>& operator++() {
++left_iter_;
@@ -186,8 +190,14 @@ class ZipLeftIter : public std::iterator<
IterRight right_iter_;
};
-class CountIter : public std::iterator<std::forward_iterator_tag, size_t, size_t, size_t, size_t> {
+class CountIter {
public:
+ using iterator_category = std::forward_iterator_tag;
+ using value_type = size_t;
+ using difference_type = size_t;
+ using pointer = size_t;
+ using reference = size_t;
+
CountIter() : count_(0) {}
explicit CountIter(size_t count) : count_(count) {}
CountIter& operator++() {
@@ -238,9 +248,14 @@ static inline IterationRange<CountIter> Range(size_t end) {
}
template <typename RealIter, typename Filter>
-struct FilterIterator
- : public std::iterator<std::forward_iterator_tag, typename RealIter::value_type> {
+struct FilterIterator {
public:
+ using iterator_category = std::forward_iterator_tag;
+ using value_type = typename RealIter::value_type;
+ using difference_type = ptrdiff_t;
+ using pointer = value_type*;
+ using reference = value_type&;
+
FilterIterator(RealIter rl,
Filter cond,
std::optional<RealIter> end = std::nullopt)
@@ -323,8 +338,14 @@ SafePrinter<Val> SafePrint(const Val* v) {
}
// Helper struct for iterating a split-string without allocation.
-struct SplitStringIter : public std::iterator<std::forward_iterator_tag, std::string_view> {
+struct SplitStringIter {
public:
+ using iterator_category = std::forward_iterator_tag;
+ using value_type = std::string_view;
+ using difference_type = ptrdiff_t;
+ using pointer = value_type*;
+ using reference = value_type&;
+
// Direct iterator constructor. The iteration state is only the current index.
// We use that with the split char and the full string to get the current and
// next segment.