[PATCH] D74683: [mlir] Add a utility iterator range that repeats a given value `n` times.
River Riddle via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 21 15:25:38 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG93813e5feb18: [mlir] Add a utility iterator range that repeats a given value `n` times. (authored by rriddle).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D74683/new/
https://reviews.llvm.org/D74683
Files:
mlir/include/mlir/Support/STLExtras.h
Index: mlir/include/mlir/Support/STLExtras.h
===================================================================
--- mlir/include/mlir/Support/STLExtras.h
+++ mlir/include/mlir/Support/STLExtras.h
@@ -339,6 +339,26 @@
});
}
+/// A range class that repeats a specific value for a set number of times.
+template <typename T>
+class RepeatRange
+ : public detail::indexed_accessor_range_base<RepeatRange<T>, T, const T> {
+public:
+ using detail::indexed_accessor_range_base<
+ RepeatRange<T>, T, const T>::indexed_accessor_range_base;
+
+ /// Given that we are repeating a specific value, we can simply return that
+ /// value when offsetting the base or dereferencing the iterator.
+ static T offset_base(const T &val, ptrdiff_t) { return val; }
+ static const T &dereference_iterator(const T &val, ptrdiff_t) { return val; }
+};
+
+/// Make a range that repeats the given value 'n' times.
+template <typename ValueTy>
+RepeatRange<ValueTy> make_repeated_range(const ValueTy &value, size_t n) {
+ return RepeatRange<ValueTy>(value, n);
+}
+
/// Returns true of the given range only contains a single element.
template <typename ContainerTy> bool has_single_element(ContainerTy &&c) {
auto it = std::begin(c), e = std::end(c);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74683.246015.patch
Type: text/x-patch
Size: 1254 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200221/a1acd82f/attachment.bin>
More information about the llvm-commits
mailing list