diff --git a/mlir/include/mlir/Support/STLExtras.h b/mlir/include/mlir/Support/STLExtras.h --- a/mlir/include/mlir/Support/STLExtras.h +++ b/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 +class RepeatRange + : public detail::indexed_accessor_range_base, T, const T> { +public: + using detail::indexed_accessor_range_base< + RepeatRange, 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 +RepeatRange make_repeated_range(const ValueTy &value, size_t n) { + return RepeatRange(value, n); +} + /// Returns true of the given range only contains a single element. template bool has_single_element(ContainerTy &&c) { auto it = std::begin(c), e = std::end(c);