[PATCH] D141327: [ADT] Add deduction guides for `MutableArrayRef`
Joe Loser via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 9 14:40:51 PST 2023
jloser created this revision.
jloser added reviewers: serge-sans-paille, MaskRay, dblaikie, kazu.
Herald added a project: All.
jloser requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Similar to https://reviews.llvm.org/D140896, this adds deduction guides for the
counterpart of `ArrayRef`: `MutableArrayRef`. The update plan is the following:
1. Add deduction guides for `MutableArrayRef`.
2. Change uses in-tree from `makeMutableArrayRef` to use deduction guides
3. Mark `makeMutableArrayRef` as deprecated for some time before removing to give downstream users time to update.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D141327
Files:
llvm/include/llvm/ADT/ArrayRef.h
Index: llvm/include/llvm/ADT/ArrayRef.h
===================================================================
--- llvm/include/llvm/ADT/ArrayRef.h
+++ llvm/include/llvm/ADT/ArrayRef.h
@@ -562,6 +562,41 @@
return ArrayRef<T>(Arr);
}
+ /// @name MutableArrayRef Deduction guides
+ /// @{
+ /// Deduction guide to construct a `MutableArrayRef` from a single element
+ template <class T> MutableArrayRef(T &OneElt) -> MutableArrayRef<T>;
+
+ /// Deduction guide to construct a `MutableArrayRef` from a pointer and
+ /// length.
+ template <class T>
+ MutableArrayRef(T *data, size_t length) -> MutableArrayRef<T>;
+
+ /// Deduction guide to construct a `MutableArrayRef` from a `SmallVector`.
+ template <class T>
+ MutableArrayRef(SmallVectorImpl<T> &Vec) -> MutableArrayRef<T>;
+
+ template <class T, unsigned N>
+ MutableArrayRef(SmallVector<T, N> &Vec) -> MutableArrayRef<T>;
+
+ /// Deduction guide to construct a `MutableArrayRef` from a `std::vector`.
+ template <class T> MutableArrayRef(std::vector<T> &Vec) -> MutableArrayRef<T>;
+
+ /// Deduction guide to construct a `MutableArrayRef` from a `std::array`.
+ template <class T, std::size_t N>
+ MutableArrayRef(std::array<T, N> &Vec) -> MutableArrayRef<T>;
+
+ /// Deduction guide to construct a `MutableArrayRef` from a `MutableArrayRef`
+ /// (no-op) (const).
+ template <class T>
+ MutableArrayRef(const MutableArrayRef<T> &Vec) -> MutableArrayRef<T>;
+
+ /// Deduction guide to construct a `MutableArrayRef` from a C array.
+ template <typename T, size_t N>
+ MutableArrayRef(T (&Arr)[N]) -> MutableArrayRef<T>;
+
+ /// @}
+
/// Construct a MutableArrayRef from a single element.
template<typename T>
MutableArrayRef<T> makeMutableArrayRef(T &OneElt) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141327.487560.patch
Type: text/x-patch
Size: 1757 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230109/c24a2849/attachment.bin>
More information about the llvm-commits
mailing list