[llvm] e969c80 - [ADT] Clean up zip iterators. NFC.

Jakub Kuderski via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 6 08:17:14 PST 2023


Author: Jakub Kuderski
Date: 2023-03-06T11:16:58-05:00
New Revision: e969c803818cf88fb586d58505e956fe02db8696

URL: https://github.com/llvm/llvm-project/commit/e969c803818cf88fb586d58505e956fe02db8696
DIFF: https://github.com/llvm/llvm-project/commit/e969c803818cf88fb586d58505e956fe02db8696.diff

LOG: [ADT] Clean up zip iterators. NFC.

*  Use inheriting constructors declarations to avoid introducing the
   `Base` typedef and duplicate constructor definitions. This should make
   things cleaner, especially since `zip_common` also exposes a `Base`
   typedef.
*  Drop unnecessary template parameters.
*  Avoid double negation in `zip_shortest`'s `operator==` and rename the
   comparison function for better readability.

Reviewed By: zero9178

Differential Revision: https://reviews.llvm.org/D145332

Added: 
    

Modified: 
    llvm/include/llvm/ADT/STLExtras.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index 0ee260bc99f2..74fbfc958bea 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -827,32 +827,28 @@ struct zip_common : public zip_traits<ZipType, Iters...> {
 };
 
 template <typename... Iters>
-struct zip_first : public zip_common<zip_first<Iters...>, Iters...> {
-  using Base = zip_common<zip_first<Iters...>, Iters...>;
+struct zip_first : zip_common<zip_first<Iters...>, Iters...> {
+  using zip_common<zip_first, Iters...>::zip_common;
 
-  bool operator==(const zip_first<Iters...> &other) const {
+  bool operator==(const zip_first &other) const {
     return std::get<0>(this->iterators) == std::get<0>(other.iterators);
   }
-
-  zip_first(Iters &&... ts) : Base(std::forward<Iters>(ts)...) {}
 };
 
 template <typename... Iters>
-class zip_shortest : public zip_common<zip_shortest<Iters...>, Iters...> {
-  template <size_t... Ns>
-  bool test(const zip_shortest<Iters...> &other,
-            std::index_sequence<Ns...>) const {
-    return ((std::get<Ns>(this->iterators) != std::get<Ns>(other.iterators)) &&
-            ...);
-  }
-
-public:
-  using Base = zip_common<zip_shortest<Iters...>, Iters...>;
+struct zip_shortest : zip_common<zip_shortest<Iters...>, Iters...> {
+  using zip_common<zip_shortest, Iters...>::zip_common;
 
-  zip_shortest(Iters &&... ts) : Base(std::forward<Iters>(ts)...) {}
+  bool operator==(const zip_shortest &other) const {
+    return any_iterator_equals(other, std::index_sequence_for<Iters...>{});
+  }
 
-  bool operator==(const zip_shortest<Iters...> &other) const {
-    return !test(other, std::index_sequence_for<Iters...>{});
+private:
+  template <size_t... Ns>
+  bool any_iterator_equals(const zip_shortest &other,
+                           std::index_sequence<Ns...>) const {
+    return ((std::get<Ns>(this->iterators) == std::get<Ns>(other.iterators)) ||
+            ...);
   }
 };
 


        


More information about the llvm-commits mailing list