This is an automated email from the ASF dual-hosted git repository.
alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new 25e7a7549 [c++17] address std::iterator deprecation warnings
25e7a7549 is described below
commit 25e7a7549cf01ac68ea2de53d68e6b710e03cd9d
Author: Alexey Serbin <[email protected]>
AuthorDate: Wed Apr 3 22:16:53 2024 -0700
[c++17] address std::iterator deprecation warnings
This patch addresses warnings about deprecation of std::iterator [1]
produced by CLANG 15 on macOS Sonoma: there were many of those generated
prior to this patch. See a blog post [2] referred from the isocpp.org
site [3] for more details.
This patch doesn't contain any functional modifications.
[1] https://en.cppreference.com/w/cpp/iterator/iterator
[2] https://www.fluentcpp.com/2018/05/08/std-iterator-deprecated/
[3]
https://isocpp.org/blog/2018/05/stditerator-is-deprecated-why-what-it-was-and-what-to-use-instead-jonathan
Change-Id: Id82af8f860156f3452a1c6522603ffacaa1ad0cd
Reviewed-on: http://gerrit.cloudera.org:8080/21240
Reviewed-by: Mahesh Reddy <[email protected]>
Reviewed-by: Abhishek Chennaka <[email protected]>
Tested-by: Alexey Serbin <[email protected]>
---
src/kudu/client/scan_batch.h | 10 +++++++++-
src/kudu/gutil/strings/join.h | 2 +-
src/kudu/gutil/strings/split_internal.h | 10 ++++++++--
src/kudu/util/bitset.h | 10 ++++++++--
4 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/src/kudu/client/scan_batch.h b/src/kudu/client/scan_batch.h
index 500253684..cef7f7609 100644
--- a/src/kudu/client/scan_batch.h
+++ b/src/kudu/client/scan_batch.h
@@ -367,6 +367,14 @@ class KUDU_EXPORT KuduScanBatch::RowPtr {
const uint8_t* row_data_;
};
+// std::iterator has been deprecated in C++17, but this code should still be
+// compilable by legacy C++98 compilers as well. It's also necessary to keep
+// backward compatibility with the ABI provided by earlier Kudu releases,
+// so modifiying the inheritance chain isn't an option. Instead of removing
+// the inheritance from std::iterator<...> and explicitly defining the types
+// required by the STL iterator traits, the deprecation warnings are silenced.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
class KUDU_EXPORT KuduScanBatch::const_iterator
: public std::iterator<std::forward_iterator_tag, KuduScanBatch::RowPtr> {
public:
@@ -435,7 +443,7 @@ class KUDU_EXPORT KuduScanBatch::const_iterator
const KuduScanBatch* const batch_;
int idx_;
};
-
+#pragma GCC diagnostic pop
inline KuduScanBatch::const_iterator KuduScanBatch::begin() const {
return const_iterator(this, 0);
diff --git a/src/kudu/gutil/strings/join.h b/src/kudu/gutil/strings/join.h
index c7c5c85d9..06f726686 100644
--- a/src/kudu/gutil/strings/join.h
+++ b/src/kudu/gutil/strings/join.h
@@ -204,7 +204,7 @@ void JoinStringsIterator(const ITERATOR& start,
// Precompute resulting length so we can reserve() memory in one shot.
if (start != end) {
- int length = delim.size()*(distance(start, end)-1);
+ auto length = delim.size() * (std::distance(start, end) - 1);
for (ITERATOR iter = start; iter != end; ++iter) {
length += iter->size();
}
diff --git a/src/kudu/gutil/strings/split_internal.h
b/src/kudu/gutil/strings/split_internal.h
index c29be8807..15f2a0993 100644
--- a/src/kudu/gutil/strings/split_internal.h
+++ b/src/kudu/gutil/strings/split_internal.h
@@ -63,9 +63,15 @@ struct NoFilter {
// The two-argument constructor is used to split the given text using the given
// delimiter.
template <typename Delimiter, typename Predicate = NoFilter>
-class SplitIterator
- : public std::iterator<std::input_iterator_tag, StringPiece> {
+class SplitIterator {
public:
+ // Types required by the iterator traits.
+ using iterator_category = std::input_iterator_tag;
+ using value_type = StringPiece;
+ using difference_type = std::ptrdiff_t;
+ using pointer = StringPiece*;
+ using reference = StringPiece&;
+
// Two constructors for "end" iterators.
explicit SplitIterator(Delimiter d)
: delimiter_(std::move(d)), predicate_(), is_end_(true) {}
diff --git a/src/kudu/util/bitset.h b/src/kudu/util/bitset.h
index 61a6274aa..a80e9c607 100644
--- a/src/kudu/util/bitset.h
+++ b/src/kudu/util/bitset.h
@@ -142,9 +142,15 @@ class FixedBitSet {
// Forward iterator class for a FixedBitSet.
template <typename IntType, size_t MaxVals>
-class FixedBitSet<IntType, MaxVals>::iterator :
- public std::iterator<std::forward_iterator_tag, IntType> {
+class FixedBitSet<IntType, MaxVals>::iterator {
public:
+ // Types required by the iterator traits.
+ using iterator_category = std::forward_iterator_tag;
+ using value_type = IntType;
+ using difference_type = std::ptrdiff_t;
+ using pointer = IntType*;
+ using reference = IntType&;
+
// Returns the value currently pointed at by this iterator.
IntType operator*() {
return static_cast<IntType>(idx_);