[PATCH] D145332: [ADT] Clean up zip iterators. NFC.
Jakub Kuderski via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 5 14:28:06 PST 2023
kuhar created this revision.
kuhar added reviewers: dblaikie, zero9178, kazu, Mogball, antiagainst, beanz, zturner, mehdi_amini.
Herald added a subscriber: hanchung.
Herald added a project: All.
kuhar requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
- 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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D145332
Files:
llvm/include/llvm/ADT/STLExtras.h
Index: llvm/include/llvm/ADT/STLExtras.h
===================================================================
--- llvm/include/llvm/ADT/STLExtras.h
+++ llvm/include/llvm/ADT/STLExtras.h
@@ -26,6 +26,7 @@
#include "llvm/Config/abi-breaking.h"
#include "llvm/Support/ErrorHandling.h"
#include <algorithm>
+#include <bits/utility.h>
#include <cassert>
#include <cstddef>
#include <cstdint>
@@ -827,32 +828,28 @@
};
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)) ||
+ ...);
}
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145332.502475.patch
Type: text/x-patch
Size: 2107 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230305/d5f3a70f/attachment.bin>
More information about the llvm-commits
mailing list